1 8 package org.lsmp.djep.vectorJep.function; 9 10 import org.lsmp.djep.vectorJep.*; 11 import org.lsmp.djep.vectorJep.values.*; 12 import org.nfunk.jep.ParseException; 13 import org.nfunk.jep.function.*; 14 import java.util.*; 15 21 public class MPower extends PostfixMathCommand implements BinaryOperatorI 22 { 23 private static Power pow = new Power(); 24 private static ExteriorProduct cross = new ExteriorProduct(); 25 26 public MPower() { 27 super(); 28 } 29 public Dimensions calcDim(Dimensions ldim,Dimensions rdim) throws ParseException 30 { 31 if(ldim.equals(Dimensions.ONE) && rdim.equals(Dimensions.ONE)) 32 return Dimensions.ONE; 33 if(ldim.equals(Dimensions.THREE) && rdim.equals(Dimensions.THREE)) 34 return Dimensions.THREE; 35 throw new ParseException("Power: both sides must be either 0 dimensional or 3D vectors"); 36 } 37 38 public MatrixValueI calcValue( 39 MatrixValueI res, 40 MatrixValueI lhs, 41 MatrixValueI rhs) throws ParseException 42 { 43 if(lhs.getDim().equals(Dimensions.ONE) 44 && rhs.getDim().equals(Dimensions.ONE)) 45 { 46 res.setEle(0,pow.power(lhs.getEle(0),rhs.getEle(0))); 47 return res; 48 } 49 if(lhs.getDim().equals(Dimensions.THREE) 50 && rhs.getDim().equals(Dimensions.THREE)) 51 { 52 return cross.calcValue(res,lhs,rhs); 53 } 54 throw new ParseException("Power: both sides must be either 0 dimensional or 3D vectors"); 55 } 56 57 public void run(Stack inStack) 58 throws ParseException 59 { 60 checkStack(inStack); 62 Object param2 = inStack.pop(); 63 Object param1 = inStack.pop(); 64 65 if(param1 instanceof MVector && param2 instanceof MVector) 66 inStack.push(cross.crosspower(param1, param2)); 67 else 68 inStack.push(pow.power(param1,param2)); 69 } 70 71 } 72 | Popular Tags |