scientific functions
This commit is contained in:
parent
155d2bfd39
commit
4cca633d09
|
@ -0,0 +1,30 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Acos extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Acos (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.acos (v.getValue ());
|
||||
|
||||
if (Double.isNaN (value))
|
||||
valueType = ValueType.ERROR;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Asin extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Asin (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.asin (v.getValue ());
|
||||
|
||||
if (Double.isNaN (value))
|
||||
valueType = ValueType.ERROR;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Atan extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Atan (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.atan (v.getValue ());
|
||||
|
||||
if (Double.isNaN (value))
|
||||
valueType = ValueType.ERROR;
|
||||
}
|
||||
}
|
|
@ -24,7 +24,14 @@ public class Choose extends Function
|
|||
public void calculate ()
|
||||
{
|
||||
source.calculate ();
|
||||
Address address = range.get ((int) source.getValue () - 1);
|
||||
int index = (int) source.getValue () - 1;
|
||||
if (index < 0 || index >= range.size ())
|
||||
{
|
||||
valueType = ValueType.NA;
|
||||
return;
|
||||
}
|
||||
|
||||
Address address = range.get (index);
|
||||
if (address == null)
|
||||
valueType = ValueType.NA;
|
||||
else
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Cos extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Cos (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.cos (v.getValue ());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Exp extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Exp (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.exp (v.getValue ());
|
||||
|
||||
if (Double.isNaN (value))
|
||||
valueType = ValueType.ERROR;
|
||||
}
|
||||
}
|
|
@ -48,6 +48,8 @@ public class Format
|
|||
val = val.substring (0, val.length () - 1);
|
||||
if (val.startsWith ("0."))
|
||||
val = val.substring (1);
|
||||
if (val.startsWith ("-0."))
|
||||
val = "-" + val.substring (2);
|
||||
|
||||
if (val.length () > colWidth && val.indexOf ('.') >= 0)
|
||||
val = val.substring (0, colWidth);
|
||||
|
|
|
@ -42,9 +42,18 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
|||
if (text.startsWith ("@ABS("))
|
||||
return new Abs (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@ACOS("))
|
||||
return new Acos (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@AND("))
|
||||
return new And (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@ASIN("))
|
||||
return new Asin (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@ATAN("))
|
||||
return new Atan (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@AVERAGE("))
|
||||
return new Average (parent, cell, text);
|
||||
|
||||
|
@ -54,9 +63,15 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
|||
if (text.startsWith ("@CHOOSE("))
|
||||
return new Choose (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@COS("))
|
||||
return new Cos (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@ERROR"))
|
||||
return new Error (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@EXP"))
|
||||
return new Exp (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@IF("))
|
||||
return new If (parent, cell, text);
|
||||
|
||||
|
@ -69,9 +84,15 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
|||
if (text.startsWith ("@ISNA("))
|
||||
return new IsNa (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@LOG10("))
|
||||
return new Log10 (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@LOOKUP("))
|
||||
return new Lookup (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@LN("))
|
||||
return new Ln (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@MIN("))
|
||||
return new Min (parent, cell, text);
|
||||
|
||||
|
@ -90,12 +111,18 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
|||
if (text.startsWith ("@PI"))
|
||||
return new Pi (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@SIN("))
|
||||
return new Sin (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@SUM("))
|
||||
return new Sum (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@SQRT("))
|
||||
return new Sqrt (parent, cell, text);
|
||||
|
||||
if (text.startsWith ("@TAN("))
|
||||
return new Tan (parent, cell, text);
|
||||
|
||||
System.out.printf ("Unknown function: [%s]%n", text);
|
||||
return new Error (parent, cell, "@ERROR");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Ln extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Ln (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.log (v.getValue ());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Log10 extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Log10 (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.log10 (v.getValue ());
|
||||
}
|
||||
}
|
|
@ -95,7 +95,7 @@ class Range implements Iterable<Address>
|
|||
|
||||
public Address get (int index)
|
||||
{
|
||||
return range.get (index);
|
||||
return index < 0 || index >= range.size () ? null : range.get (index);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Sin extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Sin (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.sin (v.getValue ());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.bytezone.diskbrowser.visicalc;
|
||||
|
||||
public class Tan extends Function
|
||||
{
|
||||
Value v;
|
||||
|
||||
Tan (Sheet parent, Cell cell, String text)
|
||||
{
|
||||
super (parent, cell, text);
|
||||
|
||||
v = new Expression (parent, cell, functionText).reduce ();
|
||||
valueType = ValueType.VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate ()
|
||||
{
|
||||
v.calculate ();
|
||||
if (!v.isValueType (ValueType.VALUE))
|
||||
{
|
||||
valueType = v.getValueType ();
|
||||
return;
|
||||
}
|
||||
|
||||
value = Math.tan (v.getValue ());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue