Esempio n. 1
0
        public ICalculonType Execute(ref ControllerState cs)
        {
            ICalculonType rhs = cs.stack.Pop();
            ICalculonType lhs = cs.stack.Pop();

            Type[] argTypes = new Type[] { lhs.GetType(), rhs.GetType() };
            if (argTypes.SequenceEqual(new Type[] { typeof(Real), typeof(Real) }) ||
                argTypes.SequenceEqual(new Type[] { typeof(Real), typeof(RealConstant) }) ||
                argTypes.SequenceEqual(new Type[] { typeof(RealConstant), typeof(Real) }) ||
                argTypes.SequenceEqual(new Type[] { typeof(Real), typeof(Integer) }) ||
                argTypes.SequenceEqual(new Type[] { typeof(RealConstant), typeof(Integer) }) ||
                argTypes.SequenceEqual(new Type[] { typeof(Integer), typeof(Real) }) ||
                argTypes.SequenceEqual(new Type[] { typeof(Integer), typeof(RealConstant) })
                )
            {
                Real left  = new Real(lhs);
                Real right = new Real(rhs);
                return(left.Pow(right));
            }
            if (argTypes.SequenceEqual(new Type[] { typeof(Integer), typeof(Integer) }))
            {
                return(((Integer)lhs).Pow((Integer)rhs));
            }
            throw new ArgumentException(
                      String.Format(Config.handle.strings["UnsupportedTypes"], argTypes));
        }