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 UMinus extends PostfixMathCommand 16 { 17 public UMinus() { 18 numberOfParameters = 1; 19 } 20 21 public void run(Stack inStack) throws ParseException { 22 checkStack(inStack); 24 Object param = inStack.pop(); 25 26 inStack.push(umin(param)); 27 return; 28 } 29 30 public Object umin(Object param) throws ParseException { 31 if (param instanceof Complex) 32 return ((Complex)param).neg(); 33 if (param instanceof Number ) 34 return new Double (-((Number )param).doubleValue()); 35 36 throw new ParseException("Invalid parameter type"); 37 } 38 } 39 | Popular Tags |