示例#1
0
        NumberElement calculate(NumberElement left, NumberElement right, OperatorElement op)
        {
            Double temp = Double.MaxValue;

            if (op.type == OperatorType.ADD)
            {
                temp = left.getNumber() + right.getNumber();
            }
            else if (op.type == OperatorType.SUBTRACT)
            {
                temp = left.getNumber() - right.getNumber();
            }
            else if (op.type == OperatorType.MULTIPLY)
            {
                temp = left.getNumber() * right.getNumber();
            }
            else if (op.type == OperatorType.DIVIDE)
            {
                temp = left.getNumber() / right.getNumber();
            }
            else if (op.type == OperatorType.EXPONENTIAL)
            {
                temp = Math.Pow(left.getNumber(), right.getNumber());
            }

            return(new NumberElement(temp.ToString()));
        }
示例#2
0
 int Precedence(OperatorElement c)
 {
     if (c.type == OperatorType.EXPONENTIAL)
     {
         return(2);
     }
     else if (c.type == OperatorType.MULTIPLY || c.type == OperatorType.DIVIDE)
     {
         return(3);
     }
     else if (c.type == OperatorType.ADD || c.type == OperatorType.SUBTRACT)
     {
         return(4);
     }
     else
     {
         return(Int32.MaxValue);
     }
 }