Exemplo n.º 1
0
        public static Complex TrueDivide(Complex x, Complex y)
        {
            if (y.IsZero())
            {
                throw new DivideByZeroException("complex division by zero");
            }

            return(x / y);
        }
Exemplo n.º 2
0
        //asin(x) = ln( x + (x*x +1)^1/2)
        public static Complex asinh(object x)
        {
            Complex num = GetComplexNum(x);

            if (num.IsZero())
            {
                // preserve -0.0 imag component
                return(MathUtils.MakeImaginary(num.Imaginary()));
            }

            Complex recip = 1 / num;

            return(log(num) + log(1 + sqrt(recip * recip + 1)));
        }
Exemplo n.º 3
0
        //ln(re^iO) = ln(r) + iO
        public static Complex log(object x)
        {
            Complex num = GetComplexNum(x);

            if (num.IsZero())
            {
                throw PythonOps.ValueError("math domain error");
            }

            double r, theta;

            r     = num.Abs();
            theta = GetAngle(num);

            return(new Complex(Math.Log(r), theta));
        }
Exemplo n.º 4
0
        public static Complex op_Power(Complex x, Complex y)
        {
            if (x.IsZero())
            {
                if (y.Real < 0.0 || y.Imaginary() != 0.0)
                {
                    throw PythonOps.ZeroDivisionError("0.0 to a negative or complex power");
                }
                return(y.IsZero() ? Complex.One : Complex.Zero);
            }

#if FEATURE_NUMERICS
            // Special case for higher precision with real integer powers
            // TODO: A similar check may get added to CLR 4 upon resolution of Dev10 bug 863171,
            // in which case this code should go away.
            if (y.Imaginary == 0.0)
            {
                int power = (int)y.Real;
                if (power >= 0 && y.Real == power)
                {
                    Complex res = Complex.One;
                    if (power == 0)
                    {
                        return(res);
                    }
                    Complex factor = x;
                    while (power != 0)
                    {
                        if ((power & 1) != 0)
                        {
                            res = res * factor;
                        }
                        factor  = factor * factor;
                        power >>= 1;
                    }
                    return(res);
                }
            }
#endif

            return(x.Pow(y));
        }
Exemplo n.º 5
0
 public static bool __bool__(Complex x)
 {
     return(!x.IsZero());
 }