コード例 #1
0
        public IOperand Power(IOperand rhs)
        {
            if (!(rhs is DoubleOperand))
            {
                throw new RPN_Exception("Argument invalid in DoubleOperand.Power : rhs");
            }
            DoubleOperand oprResult = new DoubleOperand("Result", Type.GetType("System.Double"));

            oprResult.Value = Math.Pow((Double)this.Value, (Double)((Operand)rhs).Value);
            return(oprResult);
        }
コード例 #2
0
        public IOperand Modulo(IOperand rhs)
        {
            if (!(rhs is DoubleOperand))
            {
                throw new RPN_Exception("Argument invalid in DoubleOperand.Modulo : rhs");
            }
            DoubleOperand oprResult = new DoubleOperand("Result", Type.GetType("System.Double"));

            oprResult.Value = (Double)this.Value % (Double)((Operand)rhs).Value;
            return(oprResult);
        }
コード例 #3
0
        /// <summary>
        /// Factory method to create corresponding Operands.
        /// Extended this method to create newer datatypes.
        /// </summary>
        /// <param name="szVarName"></param>
        /// <param name="varType"></param>
        /// <param name="varValue"></param>
        /// <returns></returns>
        static public Operand CreateOperand(string szVarName, Type varType, object varValue)
        {
            Operand oprResult = null;

            switch (varType.ToString())
            {
            case "System.Int32":
            case "System.Int64":
                oprResult = new LongOperand(szVarName, varValue);
                return(oprResult);

            case "System.Double":
                oprResult = new DoubleOperand(szVarName, varValue);
                return(oprResult);
                //case System.Decimal:
                //case System.Single:
                //	oprResult = new DecimalOperand( szVarName, varValue );
                //	return oprResult;
                //	break;
            }
            throw new RPN_Exception("Unhandled type : " + varType.ToString());
        }