Beispiel #1
0
        public static ComplexD Log(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if ((a.Real > 0.0) && (a.Imaginary == 0.0))
            {
                result.Real      = System.Math.Log(a.Real);
                result.Imaginary = 0.0;
            }
            else if (a.Real == 0.0)
            {
                if (a.Imaginary > 0.0)
                {
                    result.Real      = System.Math.Log(a.Imaginary);
                    result.Imaginary = MathFunctions.HalfPI;
                }
                else
                {
                    result.Real      = System.Math.Log(-(a.Imaginary));
                    result.Imaginary = -MathFunctions.HalfPI;
                }
            }
            else
            {
                result.Real      = System.Math.Log(a.GetModulus());
                result.Imaginary = System.Math.Atan2(a.Imaginary, a.Real);
            }

            return(result);
        }
Beispiel #2
0
        public static ComplexD Sqrt(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

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

                result.Real      = System.Math.Sqrt(0.5 * (modulus + a.Real));
                result.Imaginary = System.Math.Sqrt(0.5 * (modulus - a.Real));
                if (a.Imaginary < 0.0)
                {
                    result.Imaginary = -result.Imaginary;
                }
            }

            return(result);
        }