visicalc numeric formats

This commit is contained in:
Denis Molony 2017-03-13 18:16:20 +11:00
parent 4865246924
commit 7381d8e66b
10 changed files with 59 additions and 49 deletions

View File

@ -22,7 +22,7 @@ import com.bytezone.diskbrowser.wizardry.WizardryScenarioDisk;
public class DiskFactory
{
private static boolean debug = true;
private static boolean debug = false;
private DiskFactory ()
{
@ -211,11 +211,15 @@ public class DiskFactory
if (true)
{
// if (debug)
// System.out.println (" trying checksums");
long checksum = appleDisk256.getBootChecksum ();
if (checksum == 3176296590L //
if (checksum == 227968344L) // empty boot sector
{
// could be wizardry data, visialc data ...
if (debug)
System.out.println (" empty sector checksum : " + checksum);
}
else if (checksum == 3176296590L //
|| checksum == 108825457L //
|| checksum == 1439356606L //
|| checksum == 1550012074L //
@ -258,9 +262,7 @@ public class DiskFactory
else if (checksum == 2803644711L // Apple Pascal disk 0
|| checksum == 3317783349L //
|| checksum == 1728863694L // Wizardry_I_boot.dsk
|| checksum == 227968344L // wizardry_I/australia16.dsk
|| checksum == 198094178L //
|| checksum == 227968344L) // lauren.dsk
|| checksum == 198094178L) //
{
if (debug)
System.out.println (" known PASCAL checksum : " + checksum);

View File

@ -264,12 +264,12 @@ public class DosDisk extends AbstractFormattedDisk
if (buffer[53] != 16 && buffer[53] != 13) // tracks per sector
return 0;
if (buffer[49] < -1 || buffer[49] > 1) // direction of next file save
{
System.out.println ("Bad direction : " + buffer[49]);
// Visicalc data disk had 0xF8
// return 0;
}
// if (buffer[49] < -1 || buffer[49] > 1) // direction of next file save
// {
// System.out.println ("Bad direction : " + buffer[49]);
// // Visicalc data disk had 0xF8
// // return 0;
// }
int version = buffer[3];
if (version < -1 || version > 4)

View File

@ -173,9 +173,8 @@ class Cell extends AbstractValue implements Comparable<Cell>
@Override
public ValueType getValueType ()
{
if (cellType == CellType.EMPTY)
return ValueType.NA;
if (cellType == CellType.LABEL || cellType == CellType.REPEATING_CHARACTER)
if (cellType == CellType.EMPTY || cellType == CellType.LABEL
|| cellType == CellType.REPEATING_CHARACTER)
return ValueType.VALUE;
return value.getValueType ();

View File

@ -7,10 +7,4 @@ class Error extends Function
super (parent, text);
valueType = ValueType.ERROR;
}
@Override
public double getValue ()
{
return 0;
}
}

View File

@ -157,13 +157,13 @@ class Expression extends AbstractValue implements Iterable<Value>
thisValue.calculate ();
value = 0;
if (thisValue.isValueType (ValueType.ERROR))
if (!thisValue.isValueType (ValueType.VALUE))
{
valueType = thisValue.getValueType ();
return;
}
value = thisValue.getValue (); // NA returns zero
value = thisValue.getValue ();
String sign = signs.get (0);
if (sign.equals ("(-)"))
@ -174,13 +174,13 @@ class Expression extends AbstractValue implements Iterable<Value>
thisValue = values.get (i);
thisValue.calculate ();
if (thisValue.isValueType (ValueType.ERROR))
if (!thisValue.isValueType (ValueType.VALUE))
{
valueType = thisValue.getValueType ();
return;
}
double nextValue = thisValue.getValue (); // NA returns zero
double nextValue = thisValue.getValue ();
sign = signs.get (i);
if (sign.equals ("(-)"))

View File

@ -17,18 +17,33 @@ public class Format
if (actualValue == -0.0)
actualValue = 0;
String valueText = String.valueOf ((int) actualValue);
if (valueText.startsWith ("0"))
valueText = valueText.substring (1);
int digits = valueText.length ();
if (digits > colWidth)
return OVERFLOW.substring (0, colWidth);
switch (formatChar)
{
case 'L':
case 'R':
case 'G':
case ' ':
String numberFormat = String.format ("%%%d.7f", colWidth + 8);
int precision = colWidth - (digits + 1);
if (digits == 0)
precision = colWidth - 1;
if (precision < 0)
precision = 0;
String numberFormat = String.format ("%%%d.%df", colWidth, precision);
String val = String.format (numberFormat, actualValue);
// System.out.printf ("%s %2d %2d %s %15.8f %s : ", formatChar, colWidth,
// digits, numberFormat, actualValue, val);
val = val.trim ();
while (val.endsWith ("0"))
val = val.substring (0, val.length () - 1);
if (val.indexOf ('.') >= 0)
while (val.endsWith ("0"))
val = val.substring (0, val.length () - 1);
if (val.endsWith ("."))
val = val.substring (0, val.length () - 1);
if (val.startsWith ("0."))
@ -48,14 +63,16 @@ public class Format
val = String.format (rightFormat, val);
}
// System.out.printf ("[%s]%n", val);
if (val.length () > colWidth)
return OVERFLOW.substring (0, colWidth);
return val;
case 'I':
String integerFormat = String.format ("%%%dd", colWidth);
String result = String.format (integerFormat, (int) actualValue);
String integerFormat = String.format ("%%%d.0f", colWidth);
String result = String.format (integerFormat, actualValue);
if (result.length () > colWidth)
return OVERFLOW.substring (0, colWidth);
return result;

View File

@ -2,22 +2,20 @@ package com.bytezone.diskbrowser.visicalc;
class IsError extends Function
{
Cell cell;
Value expression;
public IsError (Sheet parent, String text)
{
super (parent, text);
cell = parent.getCell (functionText);
expression = new Expression (parent, functionText).reduce ();
}
@Override
public void calculate ()
{
// if (cell == null)
// cell = parent.getCell (functionText);
value = cell == null ? 1 : cell.isValueType (ValueType.ERROR) ? 1 : 0;
expression.calculate ();
value = expression.isValueType (ValueType.ERROR) ? 1 : 0;
valueType = ValueType.VALUE;
}
}

View File

@ -14,11 +14,8 @@ public class IsNa extends Function
@Override
public void calculate ()
{
// if (expression == null)
// expression = new Expression (parent, functionText);
expression.calculate ();
value = expression.getValue ();
value = expression.isValueType (ValueType.NA) ? 1 : 0;
valueType = expression.getValueType ();
}
}

View File

@ -30,6 +30,7 @@ class Lookup extends Function
if (!source.isValueType (ValueType.VALUE))
{
valueType = source.getValueType ();
// valueType = ValueType.NA;
return;
}
@ -45,15 +46,23 @@ class Lookup extends Function
for (Address address : range)
{
Cell cell = parent.getCell (address);
if (cell.isValueType (ValueType.NA))
continue;
// if (cell.isValueType (ValueType.NA))
// {
// // System.out.println ("NA1");
// break;
// // continue;
// }
if (cell.getValue () > sourceValue) // past the value
break;
target = address;
}
if (target == null)
{
valueType = ValueType.NA;
// System.out.println ("NA2");
value = 0;
}
else
{
Address adjacentAddress =

View File

@ -7,10 +7,4 @@ public class Na extends Function
super (parent, text);
valueType = ValueType.NA;
}
@Override
public double getValue ()
{
return 0;
}
}