Esempio n. 1
0
        public void GetNumericPowerTest()
        {
            // pow ( pow ( -a, 3 ), 2 ) => pow ( a, 6 )
            E      e = E.Pow(E.Pow(E.Negate(E.Num("a")), E.NumConst(3)), E.NumConst(2));
            E      e1;
            bool   isNeg;
            bool   needAbs;
            double pow = MultipleOp.GetNumericPower(e, out e1, out isNeg, out needAbs);

            Assert.IsTrue(pow == 6);

            // pow ( sqrt ( a ), 3 ) => pow ( a, 3 / 2 )
            e   = E.Pow(E.Sqrt(E.Num("a")), E.NumConst(3));
            pow = MultipleOp.GetNumericPower(e, out e1, out isNeg, out needAbs);
            Assert.IsTrue(pow == 1.5);

            // pow ( pow ( a, 1/4 ), 2 ) => pow ( a, 1 / 2 ) => sqrt ( a )
            e   = E.Pow(E.Pow(E.Num("a"), E.NumConst(0.25)), E.NumConst(2));
            pow = MultipleOp.GetNumericPower(e, out e1, out isNeg, out needAbs);
            Assert.IsTrue(pow == 0.5);

            // pow ( pow ( -a, 2 ), 1.5 ) => pow ( abs ( a ), 3 )
            e   = E.Pow(E.Pow(E.Negate(E.Num("a")), E.NumConst(2)), E.NumConst(1.5));
            pow = MultipleOp.GetNumericPower(e, out e1, out isNeg, out needAbs);
            Assert.IsTrue(pow == 3);
        }
Esempio n. 2
0
        public static MultipleOp MultipleOp(MultipleOpKind opKind, params E [] operands)
        {
            var expr = new MultipleOp(opKind, operands);

            if (expr.InferredType == ExpressionType.Undefined)
            {
                throw new InvalidCastException();
            }

            return(expr);
        }