public static double Abs(Complex x) { double res = x.Abs(); if (double.IsInfinity(res) && !double.IsInfinity(x.Real) && !double.IsInfinity(x.Imaginary())) { throw PythonOps.OverflowError("absolute value too large"); } return(res); }
public static PythonTuple polar(object x) { Complex num = GetComplexNum(x); double[] res = new double[] { num.Abs(), GetAngle(num) }; // check for overflow if (double.IsInfinity(res[0]) && !IsInfinity(num)) { throw PythonOps.OverflowError("math range error"); } return(new PythonTuple(res)); }
//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)); }
public static double Abs(Complex x) { #if CLR2 double res = x.Abs(); #else // TODO: remove after CodePlex 26224 and MS internal 861649 are resolved double res = MathUtils.Hypot(x.Real, x.Imaginary); #endif if (double.IsInfinity(res) && !double.IsInfinity(x.Real) && !double.IsInfinity(x.Imaginary())) { throw PythonOps.OverflowError("absolute value too large"); } return(res); }
public static Complex sqrt(object x) { Complex num = GetComplexNum(x); if (num.Imaginary() == 0.0) { if (num.Real >= 0.0) { return(MathUtils.MakeReal(Math.Sqrt(num.Real))); } else { return(MathUtils.MakeImaginary(Math.Sqrt(-num.Real))); } } double c = num.Abs() + num.Real; double real = Math.Sqrt(0.5 * c); double imag = num.Imaginary() / Math.Sqrt(2 * c); return(new Complex(real, imag)); }