1 9 package org.nfunk.jep.function; 10 11 import java.lang.Math ; 12 import java.util.*; 13 import org.nfunk.jep.*; 14 import org.nfunk.jep.type.*; 15 16 21 public class NaturalLogarithm extends PostfixMathCommand 22 { 23 public NaturalLogarithm() 24 { 25 numberOfParameters = 1; 26 27 } 28 29 public void run(Stack inStack) 30 throws ParseException 31 { 32 checkStack(inStack); Object param = inStack.pop(); 34 inStack.push(ln(param)); return; 36 } 37 38 public Object ln(Object param) 39 throws ParseException 40 { 41 if (param instanceof Complex) 42 { 43 return ((Complex)param).log(); 44 } 45 else if (param instanceof Number ) 46 { 47 double num = ((Number ) param).doubleValue(); 49 if( num > 0) 50 return new Double (Math.log(num)); 51 else 52 { 53 Complex temp = new Complex(num); 54 return temp.log(); 55 } 56 } 57 58 throw new ParseException("Invalid parameter type"); 59 } 60 } 61 | Popular Tags |