first commit
This commit is contained in:
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");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user