More NaN handling

This commit is contained in:
Denis Molony 2016-07-21 21:28:22 +10:00
parent 0ee07d662a
commit 1c199f3c5c
5 changed files with 42 additions and 9 deletions

View File

@ -121,12 +121,10 @@ class Cell implements Comparable<Cell>, Value
return justify (repeat, colWidth);
case VALUE:
if (value.isError () || value.isNotAvailable ())
if (value.isError () || value.isNotAvailable () || value.isNotANumber ())
return justify (value.getText (), colWidth);
Double thisValue = value.getValue ();
if (thisValue.isNaN ())
return justify ("NaN", colWidth);
char format = cellFormat != ' ' ? cellFormat : defaultFormat;
if (format == 'I')
@ -210,6 +208,15 @@ class Cell implements Comparable<Cell>, Value
return value.isNotAvailable ();
}
@Override
public boolean isNotANumber ()
{
// assert type == CellType.VALUE : "Cell type: " + type;
// if (!isValue ())
// return true;
return value.isNotANumber ();
}
@Override
public Value calculate ()
{

View File

@ -173,7 +173,11 @@ class Expression implements Value
else if (operator.equals ("^"))
value = Math.pow (value, nextValue);
}
valueType = ValueType.VALUE;
if (Double.isNaN (value))
valueType = ValueType.NAN;
else
valueType = ValueType.VALUE;
}
catch (Exception e)
{
@ -202,6 +206,12 @@ class Expression implements Value
return valueType == ValueType.NA;
}
@Override
public boolean isNotANumber ()
{
return valueType == ValueType.NAN;
}
@Override
public boolean isError ()
{
@ -211,14 +221,15 @@ class Expression implements Value
@Override
public double getValue ()
{
assert valueType == ValueType.VALUE : "Expression ValueType = " + valueType;
// assert valueType == ValueType.VALUE : "Expression ValueType = " + valueType;
return value;
}
@Override
public String getText ()
{
return isNotAvailable () ? "NA" : isError () ? "Error" : "";
return isNotAvailable () ? "NA" : isError () ? "Error" : isNotANumber () ? "NaN" : "";
// return isNotAvailable () ? "NA" : isError () ? "Error" : "";
}
private String checkBrackets (String input)

View File

@ -139,6 +139,12 @@ abstract class Function implements Value
return valueType == ValueType.NA;
}
@Override
public boolean isNotANumber ()
{
return valueType == ValueType.NAN;
}
@Override
public double getValue ()
{
@ -150,7 +156,7 @@ abstract class Function implements Value
@Override
public String getText ()
{
return isNotAvailable () ? "" : isError () ? "Error" : "";
return isNotAvailable () ? "NA" : isError () ? "Error" : isNotANumber () ? "NaN" : "";
}
protected Range getRange (String text)

View File

@ -36,6 +36,12 @@ class Number implements Value
return valueType == ValueType.NA;
}
@Override
public boolean isNotANumber ()
{
return valueType == ValueType.NAN;
}
@Override
public String toString ()
{
@ -51,7 +57,8 @@ class Number implements Value
@Override
public String getText ()
{
return valueType == ValueType.ERROR ? "Error" : "";
return isNotAvailable () ? "NA" : isError () ? "Error" : isNotANumber () ? "NaN" : "";
// return valueType == ValueType.ERROR ? "Error" : "";
}
@Override

View File

@ -4,7 +4,7 @@ interface Value
{
enum ValueType
{
VALUE, ERROR, NA
VALUE, ERROR, NA, NAN
}
public ValueType getValueType ();
@ -19,5 +19,7 @@ interface Value
public boolean isNotAvailable ();
public boolean isNotANumber ();
public Value calculate ();
}