Beispiel #1
0
        public static Complex FloorDivide(CodeContext context, Complex x, Complex y)
        {
            PythonOps.Warn(context, PythonExceptions.DeprecationWarning, "complex divmod(), // and % are deprecated");
            Complex quotient = Divide(x, y);

            return(MathUtils.MakeReal(PythonOps.CheckMath(Math.Floor(quotient.Real))));
        }
Beispiel #2
0
        public static double Power(double x, double y)
        {
            if (x == 1.0 || y == 0.0)
            {
                return(1.0);
            }
            else if (double.IsNaN(x) || double.IsNaN(y))
            {
                return(double.NaN);
            }
            else if (x == 0.0)
            {
                if (y > 0.0)
                {
                    // preserve sign if y is a positive, odd int
                    if (y % 2.0 == 1.0)
                    {
                        return(x);
                    }
                    return(0.0);
                }
                else if (y == 0.0)
                {
                    return(1.0);
                }
                else if (double.IsNegativeInfinity(y))
                {
                    return(double.PositiveInfinity);
                }
                throw PythonOps.ZeroDivisionError("0.0 cannot be raised to a negative power");
            }
            else if (double.IsPositiveInfinity(y))
            {
                if (x > 1.0 || x < -1.0)
                {
                    return(double.PositiveInfinity);
                }
                else if (x == -1.0)
                {
                    return(1.0);
                }
                return(0.0);
            }
            else if (double.IsNegativeInfinity(y))
            {
                if (x > 1.0 || x < -1.0)
                {
                    return(0.0);
                }
                else if (x == -1.0)
                {
                    return(1.0);
                }
                return(double.PositiveInfinity);
            }
            else if (double.IsNegativeInfinity(x))
            {
                // preserve negative sign if y is an odd int
                if (Math.Abs(y % 2.0) == 1.0)
                {
                    return(y > 0 ? double.NegativeInfinity : NegativeZero);
                }
                else
                {
                    return(y > 0 ? double.PositiveInfinity : 0.0);
                }
            }
            else if (x < 0 && (Math.Floor(y) != y))
            {
                throw PythonOps.ValueError("negative number cannot be raised to fraction");
            }

            return(PythonOps.CheckMath(x, y, Math.Pow(x, y)));
        }
Beispiel #3
0
        public static Complex FloorDivide(CodeContext context, Complex x, Complex y)
        {
            Complex quotient = Divide(x, y);

            return(MathUtils.MakeReal(PythonOps.CheckMath(Math.Floor(quotient.Real))));
        }