1 9 10 package org.nfunk.jep.function; 11 12 import java.util.*; 13 import org.nfunk.jep.*; 14 15 public class Logical extends PostfixMathCommand 16 { 17 int id; 18 public static final int AND = 0; 19 public static final int OR = 1; 20 public Logical(int id_in) 21 { 22 id = id_in; 23 numberOfParameters = 2; 24 } 25 26 public void run(Stack inStack) 27 throws ParseException 28 { 29 checkStack(inStack); 31 Object param2 = inStack.pop(); 32 Object param1 = inStack.pop(); 33 34 35 if ((param1 instanceof Number ) && (param2 instanceof Number )) 36 { 37 double x = ((Number )param1).doubleValue(); 38 double y = ((Number )param2).doubleValue(); 39 int r; 40 41 switch (id) 42 { 43 case 0: 44 r = ((x!=0d) && (y!=0d)) ? 1 : 0; 46 break; 47 case 1: 48 r = ((x!=0d) || (y!=0d)) ? 1 : 0; 50 break; 51 default: 52 r = 0; 53 } 54 55 inStack.push(new Double (r)); } 57 else 58 { 59 throw new ParseException("Invalid parameter type"); 60 } 61 return; 62 } 63 } 64 | Popular Tags |