first commit
This commit is contained in:
21
hrmsEjb/org/nfunk/jep/function/Abs.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Abs.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Abs extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(abs(object));
|
||||
}
|
||||
|
||||
public Object abs(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).abs());
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.abs(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
46
hrmsEjb/org/nfunk/jep/function/Add.java
Normal file
46
hrmsEjb/org/nfunk/jep/function/Add.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Add extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
for (byte b = 1; b < this.curNumberOfParameters; b++) {
|
||||
Object object1 = paramStack.pop();
|
||||
object = add(object1, object);
|
||||
}
|
||||
paramStack.push(object);
|
||||
}
|
||||
|
||||
public Object add(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return add((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return add((Complex)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return add((Complex)paramObject2, (Number)paramObject1);
|
||||
if (paramObject2 instanceof Number)
|
||||
return add((Number)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof String && paramObject2 instanceof String) {
|
||||
return (String)paramObject1 + (String)paramObject2;
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double add(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() + paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex add(Complex paramComplex1, Complex paramComplex2) {
|
||||
return new Complex(paramComplex1.re() + paramComplex2.re(), paramComplex1.im() + paramComplex2.im());
|
||||
}
|
||||
|
||||
public Complex add(Complex paramComplex, Number paramNumber) {
|
||||
return new Complex(paramComplex.re() + paramNumber.doubleValue(), paramComplex.im());
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/ArcCosine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/ArcCosine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcCosine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(acos(object));
|
||||
}
|
||||
|
||||
public Object acos(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).acos();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.acos(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
28
hrmsEjb/org/nfunk/jep/function/ArcCosineH.java
Normal file
28
hrmsEjb/org/nfunk/jep/function/ArcCosineH.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcCosineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(acosh(object));
|
||||
}
|
||||
|
||||
public Object acosh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).acosh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d >= 1.0D) {
|
||||
double d1 = Math.log(d + Math.sqrt(d * d - 1.0D));
|
||||
return new Double(d1);
|
||||
}
|
||||
Complex complex = new Complex(((Number)paramObject).doubleValue(), 0.0D);
|
||||
return complex.acosh();
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/ArcSine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/ArcSine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcSine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(asin(object));
|
||||
}
|
||||
|
||||
public Object asin(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).asin();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.asin(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
24
hrmsEjb/org/nfunk/jep/function/ArcSineH.java
Normal file
24
hrmsEjb/org/nfunk/jep/function/ArcSineH.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcSineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(asinh(object));
|
||||
}
|
||||
|
||||
public Object asinh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).asinh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d1 = ((Number)paramObject).doubleValue();
|
||||
double d2 = Math.log(d1 + Math.sqrt(d1 * d1 + 1.0D));
|
||||
return new Double(d2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
28
hrmsEjb/org/nfunk/jep/function/ArcTanH.java
Normal file
28
hrmsEjb/org/nfunk/jep/function/ArcTanH.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcTanH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(atanh(object));
|
||||
}
|
||||
|
||||
public Object atanh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).atanh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d > -1.0D && d < 1.0D) {
|
||||
double d1 = Math.log((1.0D + d) / (1.0D - d)) / 2.0D;
|
||||
return new Double(d1);
|
||||
}
|
||||
Complex complex = new Complex(d, 0.0D);
|
||||
return complex.atanh();
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/ArcTangent.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/ArcTangent.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcTangent extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(atan(object));
|
||||
}
|
||||
|
||||
public Object atan(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).atan();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.atan(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
19
hrmsEjb/org/nfunk/jep/function/ArcTangent2.java
Normal file
19
hrmsEjb/org/nfunk/jep/function/ArcTangent2.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class ArcTangent2 extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
double d1 = ((Number)number2).doubleValue();
|
||||
double d2 = ((Number)number1).doubleValue();
|
||||
paramStack.push(new Double(Math.atan2(d1, d2)));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/Arg.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/Arg.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Arg extends PostfixMathCommand {
|
||||
private static final Double ONE = new Double(1.0D);
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(arg(object));
|
||||
}
|
||||
|
||||
public Number arg(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).arg());
|
||||
if (paramObject instanceof Number)
|
||||
return ONE;
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
26
hrmsEjb/org/nfunk/jep/function/Assign.java
Normal file
26
hrmsEjb/org/nfunk/jep/function/Assign.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ASTVarNode;
|
||||
import org.nfunk.jep.Node;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.ParserVisitor;
|
||||
import org.nfunk.jep.Variable;
|
||||
|
||||
public class Assign extends PostfixMathCommand implements SpecialEvaluationI {
|
||||
public Object evaluate(Node paramNode, Object paramObject, ParserVisitor paramParserVisitor, Stack paramStack) throws ParseException {
|
||||
if (paramNode.jjtGetNumChildren() != 2)
|
||||
throw new ParseException("Assignment opperator must have 2 operators.");
|
||||
paramNode.jjtGetChild(1).jjtAccept(paramParserVisitor, paramObject);
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.peek();
|
||||
Node node = paramNode.jjtGetChild(0);
|
||||
if (node instanceof ASTVarNode) {
|
||||
ASTVarNode aSTVarNode = (ASTVarNode)node;
|
||||
Variable variable = aSTVarNode.getVar();
|
||||
variable.setValue(object);
|
||||
return object;
|
||||
}
|
||||
throw new ParseException("Assignment should have a variable for the lhs.");
|
||||
}
|
||||
}
|
121
hrmsEjb/org/nfunk/jep/function/Comparative.java
Normal file
121
hrmsEjb/org/nfunk/jep/function/Comparative.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Comparative extends PostfixMathCommand {
|
||||
int id;
|
||||
|
||||
double tolerance;
|
||||
|
||||
public static final int LT = 0;
|
||||
|
||||
public static final int GT = 1;
|
||||
|
||||
public static final int LE = 2;
|
||||
|
||||
public static final int GE = 3;
|
||||
|
||||
public static final int NE = 4;
|
||||
|
||||
public static final int EQ = 5;
|
||||
|
||||
public Comparative(int paramInt) {
|
||||
this.id = paramInt;
|
||||
this.numberOfParameters = 2;
|
||||
this.tolerance = 1.0E-6D;
|
||||
}
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
boolean bool = false;
|
||||
switch (this.id) {
|
||||
case 0:
|
||||
bool = lt(object2, object1);
|
||||
break;
|
||||
case 1:
|
||||
bool = gt(object2, object1);
|
||||
break;
|
||||
case 2:
|
||||
bool = le(object2, object1);
|
||||
break;
|
||||
case 3:
|
||||
bool = ge(object2, object1);
|
||||
break;
|
||||
case 4:
|
||||
bool = ne(object2, object1);
|
||||
break;
|
||||
case 5:
|
||||
bool = eq(object2, object1);
|
||||
break;
|
||||
}
|
||||
if (bool) {
|
||||
paramStack.push(new Double(1.0D));
|
||||
} else {
|
||||
paramStack.push(new Double(0.0D));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean lt(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException("< not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 < d2);
|
||||
}
|
||||
throw new ParseException("< not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean gt(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException("> not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 > d2);
|
||||
}
|
||||
throw new ParseException("> not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean le(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException("<= not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 <= d2);
|
||||
}
|
||||
throw new ParseException("<= not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean ge(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException(">= not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 >= d2);
|
||||
}
|
||||
throw new ParseException(">= not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean eq(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
return (paramObject1 instanceof Complex && paramObject2 instanceof Complex) ? ((Complex)paramObject1).equals((Complex)paramObject2, this.tolerance) : ((paramObject1 instanceof Complex && paramObject2 instanceof Double) ? ((Complex)paramObject1).equals(new Complex((Number)paramObject2), this.tolerance) : ((paramObject2 instanceof Complex && paramObject1 instanceof Double) ? ((Complex)paramObject2).equals(new Complex((Number)paramObject1), this.tolerance) : paramObject1.equals(paramObject2)));
|
||||
}
|
||||
|
||||
public boolean ne(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
return (paramObject1 instanceof Complex && paramObject2 instanceof Complex) ? (!((Complex)paramObject1).equals((Complex)paramObject2, this.tolerance)) : ((paramObject1 instanceof Complex && paramObject2 instanceof Double) ? (!((Complex)paramObject1).equals(new Complex((Number)paramObject2), this.tolerance)) : ((paramObject2 instanceof Complex && paramObject1 instanceof Double) ? (!((Complex)paramObject2).equals(new Complex((Number)paramObject1), this.tolerance)) : (!paramObject1.equals(paramObject2))));
|
||||
}
|
||||
|
||||
public double getTolerance() {
|
||||
return this.tolerance;
|
||||
}
|
||||
|
||||
public void setTolerance(double paramDouble) {
|
||||
this.tolerance = paramDouble;
|
||||
}
|
||||
}
|
20
hrmsEjb/org/nfunk/jep/function/ComplexPFMC.java
Normal file
20
hrmsEjb/org/nfunk/jep/function/ComplexPFMC.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ComplexPFMC extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
double d1 = ((Number)number2).doubleValue();
|
||||
double d2 = ((Number)number1).doubleValue();
|
||||
paramStack.push(new Complex(d1, d2));
|
||||
} else {
|
||||
throw new ParseException("Complex: Invalid parameter types " + number2.getClass().getName() + " " + number2.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Cosine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Cosine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Cosine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(cos(object));
|
||||
}
|
||||
|
||||
public Object cos(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).cos();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.cos(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/CosineH.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/CosineH.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class CosineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(cosh(object));
|
||||
}
|
||||
|
||||
public Object cosh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).cosh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return new Double((Math.exp(d) + Math.exp(-d)) / 2.0D);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
39
hrmsEjb/org/nfunk/jep/function/Cross.java
Normal file
39
hrmsEjb/org/nfunk/jep/function/Cross.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Cross extends PostfixMathCommand {
|
||||
static Subtract sub = new Subtract();
|
||||
|
||||
static Multiply mul = new Multiply();
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(cross(object2, object1));
|
||||
}
|
||||
|
||||
public Object cross(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Vector && paramObject2 instanceof Vector)
|
||||
return cross((Vector)paramObject1, (Vector)paramObject2);
|
||||
throw new ParseException("Cross: Invalid parameter type, both arguments must be vectors");
|
||||
}
|
||||
|
||||
public Object cross(Vector paramVector1, Vector paramVector2) throws ParseException {
|
||||
int i = paramVector1.size();
|
||||
if ((i != 2 && i != 3) || i != paramVector2.size())
|
||||
throw new ParseException("Cross: both sides must be of length 3");
|
||||
if (i == 3) {
|
||||
Vector vector = new Vector(3);
|
||||
vector.setSize(3);
|
||||
vector.setElementAt(sub.sub(mul.mul(paramVector1.elementAt(1), paramVector2.elementAt(2)), mul.mul(paramVector1.elementAt(2), paramVector2.elementAt(1))), 0);
|
||||
vector.setElementAt(sub.sub(mul.mul(paramVector1.elementAt(2), paramVector2.elementAt(0)), mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(2))), 1);
|
||||
vector.setElementAt(sub.sub(mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(1)), mul.mul(paramVector1.elementAt(1), paramVector2.elementAt(0))), 2);
|
||||
return vector;
|
||||
}
|
||||
return sub.sub(mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(1)), mul.mul(paramVector1.elementAt(1), paramVector2.elementAt(0)));
|
||||
}
|
||||
}
|
84
hrmsEjb/org/nfunk/jep/function/Divide.java
Normal file
84
hrmsEjb/org/nfunk/jep/function/Divide.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Divide extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(div(object2, object1));
|
||||
}
|
||||
|
||||
public Object div(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return div((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return div((Complex)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return div((Complex)paramObject1, (Vector)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return div((Number)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return div((Number)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return div((Number)paramObject1, (Vector)paramObject2);
|
||||
} else if (paramObject1 instanceof Vector) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return div((Vector)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return div((Vector)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double div(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() / paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex div(Complex paramComplex1, Complex paramComplex2) {
|
||||
return paramComplex1.div(paramComplex2);
|
||||
}
|
||||
|
||||
public Complex div(Number paramNumber, Complex paramComplex) {
|
||||
Complex complex = new Complex(paramNumber.doubleValue(), 0.0D);
|
||||
return complex.div(paramComplex);
|
||||
}
|
||||
|
||||
public Complex div(Complex paramComplex, Number paramNumber) {
|
||||
return new Complex(paramComplex.re() / paramNumber.doubleValue(), paramComplex.im() / paramNumber.doubleValue());
|
||||
}
|
||||
|
||||
public Vector div(Vector paramVector, Number paramNumber) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramVector.elementAt(b), paramNumber));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector div(Number paramNumber, Vector paramVector) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramNumber, paramVector.elementAt(b)));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector div(Vector paramVector, Complex paramComplex) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramVector.elementAt(b), paramComplex));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector div(Complex paramComplex, Vector paramVector) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramComplex, paramVector.elementAt(b)));
|
||||
return vector;
|
||||
}
|
||||
}
|
36
hrmsEjb/org/nfunk/jep/function/Dot.java
Normal file
36
hrmsEjb/org/nfunk/jep/function/Dot.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Dot extends PostfixMathCommand {
|
||||
static Add add = new Add();
|
||||
|
||||
static Multiply mul = new Multiply();
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(dot(object2, object1));
|
||||
}
|
||||
|
||||
public Object dot(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Vector && paramObject2 instanceof Vector)
|
||||
return dot((Vector)paramObject1, (Vector)paramObject2);
|
||||
throw new ParseException("Dot: Invalid parameter type, both arguments must be vectors");
|
||||
}
|
||||
|
||||
public Object dot(Vector paramVector1, Vector paramVector2) throws ParseException {
|
||||
if (paramVector1.size() != paramVector2.size())
|
||||
throw new ParseException("Dot: both sides of dot must be same length");
|
||||
int i = paramVector1.size();
|
||||
if (i < 1)
|
||||
throw new ParseException("Dot: empty vectors parsed");
|
||||
Object object = mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(0));
|
||||
for (byte b = 1; b < i; b++)
|
||||
object = add.add(object, mul.mul(paramVector1.elementAt(b), paramVector2.elementAt(b)));
|
||||
return object;
|
||||
}
|
||||
}
|
26
hrmsEjb/org/nfunk/jep/function/Exp.java
Normal file
26
hrmsEjb/org/nfunk/jep/function/Exp.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Exp extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(exp(object));
|
||||
}
|
||||
|
||||
public Object exp(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex) {
|
||||
Complex complex = (Complex)paramObject;
|
||||
double d1 = complex.re();
|
||||
double d2 = complex.im();
|
||||
double d3 = Math.exp(d1);
|
||||
return new Complex(d3 * Math.cos(d2), d3 * Math.sin(d2));
|
||||
}
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.exp(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
34
hrmsEjb/org/nfunk/jep/function/If.java
Normal file
34
hrmsEjb/org/nfunk/jep/function/If.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.Node;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.ParserVisitor;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class If extends PostfixMathCommand implements SpecialEvaluationI {
|
||||
public Object evaluate(Node paramNode, Object paramObject, ParserVisitor paramParserVisitor, Stack paramStack) throws ParseException {
|
||||
double d;
|
||||
int i = paramNode.jjtGetNumChildren();
|
||||
if (i < 3 || i > 4)
|
||||
throw new ParseException("If operator must have 3 or 4 arguments.");
|
||||
paramNode.jjtGetChild(0).jjtAccept(paramParserVisitor, paramObject);
|
||||
checkStack(paramStack);
|
||||
Double double_ = (Double)paramStack.pop();
|
||||
if (double_ instanceof Double) {
|
||||
d = ((Double)double_).doubleValue();
|
||||
} else if (double_ instanceof Complex) {
|
||||
d = ((Complex)double_).re();
|
||||
} else {
|
||||
throw new ParseException("Condition in if operator must be double or complex");
|
||||
}
|
||||
if (d > 0.0D) {
|
||||
paramNode.jjtGetChild(1).jjtAccept(paramParserVisitor, paramObject);
|
||||
} else if (i == 3 || d < 0.0D) {
|
||||
paramNode.jjtGetChild(2).jjtAccept(paramParserVisitor, paramObject);
|
||||
} else {
|
||||
paramNode.jjtGetChild(3).jjtAccept(paramParserVisitor, paramObject);
|
||||
}
|
||||
return paramObject;
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Imaginary.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Imaginary.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Imaginary extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(im(object));
|
||||
}
|
||||
|
||||
public Number im(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).im());
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(0.0D);
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
20
hrmsEjb/org/nfunk/jep/function/List.java
Normal file
20
hrmsEjb/org/nfunk/jep/function/List.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class List extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
if (this.curNumberOfParameters < 1)
|
||||
throw new ParseException("Empty list");
|
||||
Vector vector = new Vector(this.curNumberOfParameters);
|
||||
vector.setSize(this.curNumberOfParameters);
|
||||
for (int i = this.curNumberOfParameters - 1; i >= 0; i--) {
|
||||
Object object = paramStack.pop();
|
||||
vector.setElementAt(object, i);
|
||||
}
|
||||
paramStack.push(vector);
|
||||
}
|
||||
}
|
30
hrmsEjb/org/nfunk/jep/function/Logarithm.java
Normal file
30
hrmsEjb/org/nfunk/jep/function/Logarithm.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Logarithm extends PostfixMathCommand {
|
||||
private static final double LOG10 = Math.log(10.0D);
|
||||
|
||||
private static final Complex CLOG10 = new Complex(Math.log(10.0D), 0.0D);
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(log(object));
|
||||
}
|
||||
|
||||
public Object log(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).log().div(CLOG10);
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d > 0.0D)
|
||||
return new Double(Math.log(d) / LOG10);
|
||||
Complex complex = new Complex(d);
|
||||
return complex.log().div(CLOG10);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
42
hrmsEjb/org/nfunk/jep/function/Logical.java
Normal file
42
hrmsEjb/org/nfunk/jep/function/Logical.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Logical extends PostfixMathCommand {
|
||||
int id;
|
||||
|
||||
public static final int AND = 0;
|
||||
|
||||
public static final int OR = 1;
|
||||
|
||||
public Logical(int paramInt) {
|
||||
this.id = paramInt;
|
||||
this.numberOfParameters = 2;
|
||||
}
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
boolean bool;
|
||||
double d1 = ((Number)number2).doubleValue();
|
||||
double d2 = ((Number)number1).doubleValue();
|
||||
switch (this.id) {
|
||||
case 0:
|
||||
bool = (d1 != 0.0D && d2 != 0.0D) ? true : false;
|
||||
break;
|
||||
case 1:
|
||||
bool = (d1 != 0.0D || d2 != 0.0D) ? true : false;
|
||||
break;
|
||||
default:
|
||||
bool = false;
|
||||
break;
|
||||
}
|
||||
paramStack.push(new Double(bool));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
20
hrmsEjb/org/nfunk/jep/function/Modulus.java
Normal file
20
hrmsEjb/org/nfunk/jep/function/Modulus.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Modulus extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
double d1 = ((Number)number1).doubleValue();
|
||||
double d2 = ((Number)number2).doubleValue();
|
||||
double d3 = d2 % d1;
|
||||
paramStack.push(new Double(d3));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
68
hrmsEjb/org/nfunk/jep/function/Multiply.java
Normal file
68
hrmsEjb/org/nfunk/jep/function/Multiply.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Multiply extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
for (byte b = 1; b < this.curNumberOfParameters; b++) {
|
||||
Object object1 = paramStack.pop();
|
||||
object = mul(object1, object);
|
||||
}
|
||||
paramStack.push(object);
|
||||
}
|
||||
|
||||
public Object mul(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return mul((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return mul((Complex)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return mul((Vector)paramObject2, (Complex)paramObject1);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return mul((Complex)paramObject2, (Number)paramObject1);
|
||||
if (paramObject2 instanceof Number)
|
||||
return mul((Number)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return mul((Vector)paramObject2, (Number)paramObject1);
|
||||
} else if (paramObject1 instanceof Vector) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return mul((Vector)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return mul((Vector)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double mul(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() * paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex mul(Complex paramComplex1, Complex paramComplex2) {
|
||||
return paramComplex1.mul(paramComplex2);
|
||||
}
|
||||
|
||||
public Complex mul(Complex paramComplex, Number paramNumber) {
|
||||
return paramComplex.mul(paramNumber.doubleValue());
|
||||
}
|
||||
|
||||
public Vector mul(Vector paramVector, Number paramNumber) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(mul(paramVector.elementAt(b), paramNumber));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector mul(Vector paramVector, Complex paramComplex) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(mul(paramComplex, paramVector.elementAt(b)));
|
||||
return vector;
|
||||
}
|
||||
}
|
26
hrmsEjb/org/nfunk/jep/function/NaturalLogarithm.java
Normal file
26
hrmsEjb/org/nfunk/jep/function/NaturalLogarithm.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class NaturalLogarithm extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(ln(object));
|
||||
}
|
||||
|
||||
public Object ln(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).log();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d > 0.0D)
|
||||
return new Double(Math.log(d));
|
||||
Complex complex = new Complex(d);
|
||||
return complex.log();
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
17
hrmsEjb/org/nfunk/jep/function/Not.java
Normal file
17
hrmsEjb/org/nfunk/jep/function/Not.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Not extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number = (Number)paramStack.pop();
|
||||
if (number instanceof Number) {
|
||||
boolean bool = (((Number)number).doubleValue() == 0.0D) ? true : false;
|
||||
paramStack.push(new Double(bool));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
18
hrmsEjb/org/nfunk/jep/function/Polar.java
Normal file
18
hrmsEjb/org/nfunk/jep/function/Polar.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Polar extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
paramStack.push(Complex.polarValueOf(number2, number1));
|
||||
} else {
|
||||
throw new ParseException("Complex: Invalid parameter types " + number2.getClass().getName() + " " + number2.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
27
hrmsEjb/org/nfunk/jep/function/PostfixMathCommand.java
Normal file
27
hrmsEjb/org/nfunk/jep/function/PostfixMathCommand.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class PostfixMathCommand implements PostfixMathCommandI {
|
||||
protected int numberOfParameters = 0;
|
||||
|
||||
protected int curNumberOfParameters = 0;
|
||||
|
||||
protected void checkStack(Stack paramStack) throws ParseException {
|
||||
if (null == paramStack)
|
||||
throw new ParseException("Stack argument null");
|
||||
}
|
||||
|
||||
public int getNumberOfParameters() {
|
||||
return this.numberOfParameters;
|
||||
}
|
||||
|
||||
public void setCurNumberOfParameters(int paramInt) {
|
||||
this.curNumberOfParameters = paramInt;
|
||||
}
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
throw new ParseException("run() method of PostfixMathCommand called");
|
||||
}
|
||||
}
|
12
hrmsEjb/org/nfunk/jep/function/PostfixMathCommandI.java
Normal file
12
hrmsEjb/org/nfunk/jep/function/PostfixMathCommandI.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public interface PostfixMathCommandI {
|
||||
void run(Stack paramStack) throws ParseException;
|
||||
|
||||
int getNumberOfParameters();
|
||||
|
||||
void setCurNumberOfParameters(int paramInt);
|
||||
}
|
53
hrmsEjb/org/nfunk/jep/function/Power.java
Normal file
53
hrmsEjb/org/nfunk/jep/function/Power.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Power extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(power(object2, object1));
|
||||
}
|
||||
|
||||
public Object power(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return power((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return power((Complex)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return power((Number)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return power((Number)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Object power(Number paramNumber1, Number paramNumber2) {
|
||||
if (paramNumber1.doubleValue() < 0.0D && paramNumber2.doubleValue() != paramNumber2.intValue()) {
|
||||
Complex complex = new Complex(paramNumber1.doubleValue(), 0.0D);
|
||||
return complex.power(paramNumber2.doubleValue());
|
||||
}
|
||||
return new Double(Math.pow(paramNumber1.doubleValue(), paramNumber2.doubleValue()));
|
||||
}
|
||||
|
||||
public Object power(Complex paramComplex1, Complex paramComplex2) {
|
||||
Complex complex = paramComplex1.power(paramComplex2);
|
||||
return (complex.im() == 0.0D) ? new Double(complex.re()) : complex;
|
||||
}
|
||||
|
||||
public Object power(Complex paramComplex, Number paramNumber) {
|
||||
Complex complex = paramComplex.power(paramNumber.doubleValue());
|
||||
return (complex.im() == 0.0D) ? new Double(complex.re()) : complex;
|
||||
}
|
||||
|
||||
public Object power(Number paramNumber, Complex paramComplex) {
|
||||
Complex complex1 = new Complex(paramNumber.doubleValue(), 0.0D);
|
||||
Complex complex2 = complex1.power(paramComplex);
|
||||
return (complex2.im() == 0.0D) ? new Double(complex2.re()) : complex2;
|
||||
}
|
||||
}
|
11
hrmsEjb/org/nfunk/jep/function/Random.java
Normal file
11
hrmsEjb/org/nfunk/jep/function/Random.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Random extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
paramStack.push(new Double(Math.random()));
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Real.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Real.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Real extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(re(object));
|
||||
}
|
||||
|
||||
public Number re(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).re());
|
||||
if (paramObject instanceof Number)
|
||||
return (Number)paramObject;
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Sine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Sine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Sine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(sin(object));
|
||||
}
|
||||
|
||||
public Object sin(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).sin();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.sin(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/SineH.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/SineH.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class SineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(sinh(object));
|
||||
}
|
||||
|
||||
public Object sinh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).sinh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return new Double((Math.exp(d) - Math.exp(-d)) / 2.0D);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
10
hrmsEjb/org/nfunk/jep/function/SpecialEvaluationI.java
Normal file
10
hrmsEjb/org/nfunk/jep/function/SpecialEvaluationI.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.Node;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.ParserVisitor;
|
||||
|
||||
public interface SpecialEvaluationI {
|
||||
Object evaluate(Node paramNode, Object paramObject, ParserVisitor paramParserVisitor, Stack paramStack) throws ParseException;
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/SquareRoot.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/SquareRoot.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class SquareRoot extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(sqrt(object));
|
||||
}
|
||||
|
||||
public Object sqrt(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).sqrt();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return (d < 0.0D) ? (new Complex(d)).sqrt() : new Double(Math.sqrt(d));
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
12
hrmsEjb/org/nfunk/jep/function/Str.java
Normal file
12
hrmsEjb/org/nfunk/jep/function/Str.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Str extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(object.toString());
|
||||
}
|
||||
}
|
45
hrmsEjb/org/nfunk/jep/function/Subtract.java
Normal file
45
hrmsEjb/org/nfunk/jep/function/Subtract.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Subtract extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(sub(object2, object1));
|
||||
}
|
||||
|
||||
public Object sub(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return sub((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return sub((Complex)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return sub((Number)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return sub((Number)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double sub(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() - paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex sub(Complex paramComplex1, Complex paramComplex2) {
|
||||
return new Complex(paramComplex1.re() - paramComplex2.re(), paramComplex1.im() - paramComplex2.im());
|
||||
}
|
||||
|
||||
public Complex sub(Complex paramComplex, Number paramNumber) {
|
||||
return new Complex(paramComplex.re() - paramNumber.doubleValue(), paramComplex.im());
|
||||
}
|
||||
|
||||
public Complex sub(Number paramNumber, Complex paramComplex) {
|
||||
return new Complex(paramNumber.doubleValue() - paramComplex.re(), -paramComplex.im());
|
||||
}
|
||||
}
|
30
hrmsEjb/org/nfunk/jep/function/Sum.java
Normal file
30
hrmsEjb/org/nfunk/jep/function/Sum.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Sum extends PostfixMathCommand {
|
||||
private Add addFun = new Add();
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
Number number2;
|
||||
if (null == paramStack)
|
||||
throw new ParseException("Stack argument null");
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
if (number1 instanceof Number) {
|
||||
number2 = number1;
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
for (byte b = 1; b < this.curNumberOfParameters; b++) {
|
||||
number1 = (Number)paramStack.pop();
|
||||
if (number1 instanceof Number) {
|
||||
number2 = this.addFun.add(number1, number2);
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
b++;
|
||||
}
|
||||
paramStack.push(number2);
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/TanH.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/TanH.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class TanH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(tanh(object));
|
||||
}
|
||||
|
||||
public Object tanh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).tanh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return new Double((Math.exp(d) - Math.exp(-d)) / (Math.pow(Math.E, d) + Math.pow(Math.E, -d)));
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Tangent.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Tangent.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Tangent extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(tan(object));
|
||||
}
|
||||
|
||||
public Object tan(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).tan();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.tan(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/UMinus.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/UMinus.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class UMinus extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(umin(object));
|
||||
}
|
||||
|
||||
public Object umin(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).neg();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(-((Number)paramObject).doubleValue());
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user