1 9 package org.nfunk.jep.function; 10 11 import java.util.*; 12 import org.nfunk.jep.*; 13 import org.nfunk.jep.type.*; 14 15 public class Imaginary extends PostfixMathCommand 16 { 17 public Imaginary() { 18 numberOfParameters = 1; 19 } 20 21 public void run(Stack inStack) throws ParseException { 22 23 checkStack(inStack); Object param = inStack.pop(); 25 inStack.push(im(param)); return; 27 } 28 29 public Number im(Object param) throws ParseException { 30 31 if (param instanceof Complex) 32 return new Double (((Complex)param).im()); 33 else if (param instanceof Number ) 34 return new Double (0); 35 36 37 throw new ParseException("Invalid parameter type"); 38 } 39 40 } 41 | Popular Tags |