27 lines
836 B
Java
27 lines
836 B
Java
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");
|
|
}
|
|
}
|