コード例 #1
0
        public double CalculateEquation(Equation equation)
        {
            ConvertToReversePolishNotation(equation);
            var computeStack = new Stack();

            foreach (var arg in _onpArguments)
            {
                if (IsVariable(arg))
                {
                    computeStack.Push(arg);
                }
                else
                {
                    var a      = computeStack.Pop();
                    var b      = computeStack.Pop();
                    var result = CalculateSingleExpression(double.Parse(a.ToString()), double.Parse(b.ToString()), (char)arg);
                    computeStack.Push(result);
                }
            }
            return(double.Parse(computeStack.Pop().ToString()));
        }