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

Log() public static method

Calculates natural (base e) logarithm of a complex number.
public static Log ( Complex a ) : Complex
a Complex A instance.
return Complex
        public static Complex Log(Complex a)
        {
            Complex result = Zero;

            if ((a.Re > 0.0) && (a.Im == 0.0))
            {
                result.Re = System.Math.Log(a.Re);
                result.Im = 0.0;
            }
            else if (a.Re == 0.0)
            {
                if (a.Im > 0.0)
                {
                    result.Re = System.Math.Log(a.Im);
                    result.Im = System.Math.PI/2.0;
                }
                else
                {
                    result.Re = System.Math.Log(-(a.Im));
                    result.Im = -System.Math.PI/2.0;
                }
            }
            else
            {
                result.Re = System.Math.Log(a.Magnitude);
                result.Im = System.Math.Atan2(a.Im, a.Re);
            }

            return result;
        }