mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-23 08:29:30 +00:00
scientific functions
This commit is contained in:
parent
155d2bfd39
commit
4cca633d09
30
src/com/bytezone/diskbrowser/visicalc/Acos.java
Normal file
30
src/com/bytezone/diskbrowser/visicalc/Acos.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
30
src/com/bytezone/diskbrowser/visicalc/Asin.java
Normal file
30
src/com/bytezone/diskbrowser/visicalc/Asin.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
30
src/com/bytezone/diskbrowser/visicalc/Atan.java
Normal file
30
src/com/bytezone/diskbrowser/visicalc/Atan.java
Normal file
|
@ -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 ()
|
public void calculate ()
|
||||||
{
|
{
|
||||||
source.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)
|
if (address == null)
|
||||||
valueType = ValueType.NA;
|
valueType = ValueType.NA;
|
||||||
else
|
else
|
||||||
|
|
27
src/com/bytezone/diskbrowser/visicalc/Cos.java
Normal file
27
src/com/bytezone/diskbrowser/visicalc/Cos.java
Normal file
|
@ -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 ());
|
||||||
|
}
|
||||||
|
}
|
30
src/com/bytezone/diskbrowser/visicalc/Exp.java
Normal file
30
src/com/bytezone/diskbrowser/visicalc/Exp.java
Normal file
|
@ -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);
|
val = val.substring (0, val.length () - 1);
|
||||||
if (val.startsWith ("0."))
|
if (val.startsWith ("0."))
|
||||||
val = val.substring (1);
|
val = val.substring (1);
|
||||||
|
if (val.startsWith ("-0."))
|
||||||
|
val = "-" + val.substring (2);
|
||||||
|
|
||||||
if (val.length () > colWidth && val.indexOf ('.') >= 0)
|
if (val.length () > colWidth && val.indexOf ('.') >= 0)
|
||||||
val = val.substring (0, colWidth);
|
val = val.substring (0, colWidth);
|
||||||
|
|
|
@ -42,9 +42,18 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
||||||
if (text.startsWith ("@ABS("))
|
if (text.startsWith ("@ABS("))
|
||||||
return new Abs (parent, cell, text);
|
return new Abs (parent, cell, text);
|
||||||
|
|
||||||
|
if (text.startsWith ("@ACOS("))
|
||||||
|
return new Acos (parent, cell, text);
|
||||||
|
|
||||||
if (text.startsWith ("@AND("))
|
if (text.startsWith ("@AND("))
|
||||||
return new And (parent, cell, text);
|
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("))
|
if (text.startsWith ("@AVERAGE("))
|
||||||
return new Average (parent, cell, text);
|
return new Average (parent, cell, text);
|
||||||
|
|
||||||
|
@ -54,9 +63,15 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
||||||
if (text.startsWith ("@CHOOSE("))
|
if (text.startsWith ("@CHOOSE("))
|
||||||
return new Choose (parent, cell, text);
|
return new Choose (parent, cell, text);
|
||||||
|
|
||||||
|
if (text.startsWith ("@COS("))
|
||||||
|
return new Cos (parent, cell, text);
|
||||||
|
|
||||||
if (text.startsWith ("@ERROR"))
|
if (text.startsWith ("@ERROR"))
|
||||||
return new Error (parent, cell, text);
|
return new Error (parent, cell, text);
|
||||||
|
|
||||||
|
if (text.startsWith ("@EXP"))
|
||||||
|
return new Exp (parent, cell, text);
|
||||||
|
|
||||||
if (text.startsWith ("@IF("))
|
if (text.startsWith ("@IF("))
|
||||||
return new If (parent, cell, text);
|
return new If (parent, cell, text);
|
||||||
|
|
||||||
|
@ -69,9 +84,15 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
||||||
if (text.startsWith ("@ISNA("))
|
if (text.startsWith ("@ISNA("))
|
||||||
return new IsNa (parent, cell, text);
|
return new IsNa (parent, cell, text);
|
||||||
|
|
||||||
|
if (text.startsWith ("@LOG10("))
|
||||||
|
return new Log10 (parent, cell, text);
|
||||||
|
|
||||||
if (text.startsWith ("@LOOKUP("))
|
if (text.startsWith ("@LOOKUP("))
|
||||||
return new Lookup (parent, cell, text);
|
return new Lookup (parent, cell, text);
|
||||||
|
|
||||||
|
if (text.startsWith ("@LN("))
|
||||||
|
return new Ln (parent, cell, text);
|
||||||
|
|
||||||
if (text.startsWith ("@MIN("))
|
if (text.startsWith ("@MIN("))
|
||||||
return new Min (parent, cell, text);
|
return new Min (parent, cell, text);
|
||||||
|
|
||||||
|
@ -90,12 +111,18 @@ abstract class Function extends AbstractValue implements Iterable<Value>
|
||||||
if (text.startsWith ("@PI"))
|
if (text.startsWith ("@PI"))
|
||||||
return new Pi (parent, cell, text);
|
return new Pi (parent, cell, text);
|
||||||
|
|
||||||
|
if (text.startsWith ("@SIN("))
|
||||||
|
return new Sin (parent, cell, text);
|
||||||
|
|
||||||
if (text.startsWith ("@SUM("))
|
if (text.startsWith ("@SUM("))
|
||||||
return new Sum (parent, cell, text);
|
return new Sum (parent, cell, text);
|
||||||
|
|
||||||
if (text.startsWith ("@SQRT("))
|
if (text.startsWith ("@SQRT("))
|
||||||
return new Sqrt (parent, cell, text);
|
return new Sqrt (parent, cell, text);
|
||||||
|
|
||||||
|
if (text.startsWith ("@TAN("))
|
||||||
|
return new Tan (parent, cell, text);
|
||||||
|
|
||||||
System.out.printf ("Unknown function: [%s]%n", text);
|
System.out.printf ("Unknown function: [%s]%n", text);
|
||||||
return new Error (parent, cell, "@ERROR");
|
return new Error (parent, cell, "@ERROR");
|
||||||
}
|
}
|
||||||
|
|
27
src/com/bytezone/diskbrowser/visicalc/Ln.java
Normal file
27
src/com/bytezone/diskbrowser/visicalc/Ln.java
Normal file
|
@ -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 ());
|
||||||
|
}
|
||||||
|
}
|
27
src/com/bytezone/diskbrowser/visicalc/Log10.java
Normal file
27
src/com/bytezone/diskbrowser/visicalc/Log10.java
Normal file
|
@ -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)
|
public Address get (int index)
|
||||||
{
|
{
|
||||||
return range.get (index);
|
return index < 0 || index >= range.size () ? null : range.get (index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
27
src/com/bytezone/diskbrowser/visicalc/Sin.java
Normal file
27
src/com/bytezone/diskbrowser/visicalc/Sin.java
Normal file
|
@ -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 ());
|
||||||
|
}
|
||||||
|
}
|
27
src/com/bytezone/diskbrowser/visicalc/Tan.java
Normal file
27
src/com/bytezone/diskbrowser/visicalc/Tan.java
Normal file
|
@ -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
Block a user