1 9 10 package org.nfunk.jep.function; 11 12 import java.util.*; 13 import org.nfunk.jep.*; 14 15 public class Modulus extends PostfixMathCommand 16 { 17 public Modulus() 18 { 19 numberOfParameters = 2; 20 } 21 22 public void run(Stack inStack) 23 throws ParseException 24 { 25 checkStack(inStack); Object param2 = inStack.pop(); 27 Object param1 = inStack.pop(); 28 29 if ((param1 instanceof Number ) && (param2 instanceof Number )) 30 { 31 double divisor = ((Number )param2).doubleValue(); 32 double dividend = ((Number )param1).doubleValue(); 33 34 double result = dividend % divisor; 35 36 inStack.push(new Double (result)); 37 } 38 else 39 { 40 throw new ParseException("Invalid parameter type"); 41 } 42 return; 43 } 44 } 45 | Popular Tags |