MakeReal() public static method

public static MakeReal ( double real ) : Complex64
real double
return Complex64
Exemplo n.º 1
0
        public Complex64 Power(Complex64 y)
        {
            double c     = y.real;
            double d     = y.imag;
            int    power = (int)c;

            if (power == c && power >= 0 && d == .0)
            {
                Complex64 result = new Complex64(1.0);
                if (power == 0)
                {
                    return(result);
                }
                Complex64 factor = this;
                while (power != 0)
                {
                    if ((power & 1) != 0)
                    {
                        result = result * factor;
                    }
                    factor  = factor * factor;
                    power >>= 1;
                }
                return(result);
            }
            else if (IsZero)
            {
                return(y.IsZero ? Complex64.MakeReal(1.0) : Complex64.MakeReal(0.0));
            }
            else
            {
                double a      = real;
                double b      = imag;
                double powers = a * a + b * b;
                double arg    = System.Math.Atan2(b, a);
                double mul    = System.Math.Pow(powers, c / 2) * System.Math.Exp(-d * arg);
                double common = c * arg + .5 * d * System.Math.Log(powers);
                return(new Complex64(mul * System.Math.Cos(common), mul * System.Math.Sin(common)));
            }
        }