string GetSubExpressionString(SubExpressionType exp) { string retVal; ArithemticOperator op = exp.GetArithmeticOperator(); string lhs = GetArithmeticExpressionString(exp.GetLHSArithmeticExpression()); string rhs = GetArithmeticExpressionString(exp.GetRHSArithmeticExpression()); string opString = ""; //Add if (op.HasAdd()) { opString = "+"; } //Subtract else if (op.HasSubtract()) { opString = "-"; } //Divide else if (op.HasDivide()) { opString = "/"; } //Multiply else if (op.HasMultiply()) { opString = "*"; } //Power else if (op.HasPower()) { opString = "^"; } //Log : assumes that RHS is the base and LHS is the number. else if (op.HasLog()) { opString = "log"; } retVal = lhs + " " + opString + " " + rhs; return(retVal); }
NodeBase CreateMathNode(SubExpressionType exp) { ArithemticOperator op = exp.GetArithmeticOperator(); OperationType operationType = OperationType.ADD; //Add if (op.HasAdd()) { operationType = OperationType.ADD; } //Subtract else if (op.HasSubtract()) { operationType = OperationType.SUBTRACT; } //Divide else if (op.HasDivide()) { operationType = OperationType.DIVIDE; } //Multiply else if (op.HasMultiply()) { operationType = OperationType.MULTIPLY; } //Power else if (op.HasPower()) { operationType = OperationType.POWER; } //Log : assumes that RHS is the base and LHS is the number. else if (op.HasLog()) { operationType = OperationType.LOG; } ArithmeticNode node = new ArithmeticNode(m_Container); node.m_OperationType = operationType; node.AddChild(CreateArithmeticNode(exp.GetLHSArithmeticExpression())); node.AddChild(CreateArithmeticNode(exp.GetRHSArithmeticExpression())); return(node); }
ConstantType EvalSubExpression(SubExpressionType exp) { ConstantType retVal = new ConstantType(); ArithemticOperator op = exp.GetArithmeticOperator(); decimal lhs = (decimal)GetFloatOrIntValue(EvaluateArithmeticExpression(exp.GetLHSArithmeticExpression())); decimal rhs = (decimal)GetFloatOrIntValue(EvaluateArithmeticExpression(exp.GetRHSArithmeticExpression())); //Add if (op.HasAdd()) { retVal.AddFloat2(new SchemaDecimal(lhs + rhs)); } //Subtract else if (op.HasSubtract()) { retVal.AddFloat2(new SchemaDecimal(lhs - rhs)); } //Divide else if (op.HasDivide()) { retVal.AddFloat2(new SchemaDecimal(lhs / rhs)); } //Multiply else if (op.HasMultiply()) { retVal.AddFloat2(new SchemaDecimal(lhs * rhs)); } //Power else if (op.HasPower()) { retVal.AddFloat2(new SchemaDecimal((decimal)Math.Pow((double)lhs, (double)rhs))); } //Log : assumes that RHS is the base and LHS is the number. else if (op.HasLog()) { retVal.AddFloat2(new SchemaDecimal((decimal)(Math.Log((double)lhs) / Math.Log((double)rhs)))); } return(retVal); }