AForge.Math.Complex.Sqrt C# (CSharp) Method

Sqrt() public static method

Calculates square root of a complex number.
public static Sqrt ( Complex a ) : Complex
a Complex A instance.
return Complex
        public static Complex Sqrt(Complex a)
        {
            Complex result = Zero;

            if ((a.Re == 0.0) && (a.Im == 0.0))
            {
                return result;
            }
            else if (a.Im == 0.0)
            {
                result.Re = (a.Re > 0) ? System.Math.Sqrt(a.Re) : System.Math.Sqrt(-a.Re);
                result.Im = 0.0;
            }
            else
            {
                double modulus = a.Magnitude;

                result.Re = System.Math.Sqrt(0.5*(modulus + a.Re));
                result.Im = System.Math.Sqrt(0.5*(modulus - a.Re));
                if (a.Im < 0.0)
                    result.Im = -result.Im;
            }

            return result;
        }