69 lines
2.5 KiB
Java
69 lines
2.5 KiB
Java
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;
|
|
}
|
|
}
|