1 13 14 package org.nfunk.jep.function; 15 16 import java.lang.Math ; 17 import java.util.*; 18 import org.nfunk.jep.*; 19 import org.nfunk.jep.type.*; 20 import org.nfunk.jep.function.PostfixMathCommand; 21 22 29 public class Exp extends PostfixMathCommand 30 { 31 public Exp() 32 { 33 numberOfParameters = 1; 34 } 35 36 public void run(Stack inStack) 37 throws ParseException 38 { 39 checkStack(inStack); Object param = inStack.pop(); 41 inStack.push(exp(param)); return; 43 } 44 45 public Object exp(Object param) 46 throws ParseException 47 { 48 if (param instanceof Complex) 49 { 50 Complex z = (Complex) param; 51 double x = z.re(); 52 double y = z.im(); 53 double mod = Math.exp(x); 54 return new Complex(mod*Math.cos(y),mod*Math.sin(y)); 55 } 56 else if (param instanceof Number ) 57 { 58 return new Double (Math.exp(((Number )param).doubleValue())); 59 } 60 61 throw new ParseException("Invalid parameter type"); 62 } 63 } 64 | Popular Tags |