private static Expression ComplexConstant(Complex64 value) { if (value.Real != 0.0) { if (value.Imag != 0.0) { return Expression.Call( typeof(Complex64).GetMethod("Make"), Expression.Constant(value.Real), Expression.Constant(value.Imag) ); } else { return Expression.Call( typeof(Complex64).GetMethod("MakeReal"), Expression.Constant(value.Real) ); } } else { return Expression.Call( typeof(Complex64).GetMethod("MakeImaginary"), Expression.Constant(value.Imag) ); } }
public static Complex64 Atan(Complex64 z) { return(i / 2 * Log((i + z) / (i - z))); }
public static Complex64 Divide(Complex64 x, Complex64 y) { return x / y; }
public static Complex64 Pow(this Complex64 self, Complex64 power) { return self.Power(power); }
public static Complex64 Atan(Complex64 z) { return i/2 * Log((i + z)/(i - z)); }
public static Complex64 Pow(Complex64 baseNumber, Complex64 index) { return Exp(index * Log(baseNumber)); }
public static Complex64 Tan(Complex64 z) { return Sin(z) / Cos(z); }
public static bool LessThan(Complex x, Complex y) { throw PythonOps.TypeError("complex is not an ordered type"); }
public static bool GreaterThanOrEqual(Complex x, Complex y) { throw PythonOps.TypeError("complex is not an ordered type"); }
public static int __int__(Complex self) { throw PythonOps.TypeError(" can't convert complex to int; use int(abs(z))"); }
public static BigInteger __long__(Complex self) { throw PythonOps.TypeError("can't convert complex to long; use long(abs(z))"); }
// report the same errors as CPython for these invalid conversions public static double __float__(Complex self) { throw PythonOps.TypeError("can't convert complex to float; use abs(z)"); }
public static string __repr__(CodeContext /*!*/ context, Complex x) { return(__str__(context, x)); }
public static Complex64 Atanh(Complex64 z) { throw new NotImplementedException(); }
public static Complex64 Multiply(Complex64 x, Complex64 y) { return(x * y); }
public static object __new__( CodeContext context, PythonType cls, [DefaultParameterValue(null)] object real, [DefaultParameterValue(null)] object imag ) { Complex real2, imag2; real2 = imag2 = new Complex(); if (real == null && imag == null && cls == TypeCache.Complex) { throw PythonOps.TypeError("argument must be a string or a number"); } if (imag != null) { if (real is string) { throw PythonOps.TypeError("complex() can't take second arg if first is a string"); } if (imag is string) { throw PythonOps.TypeError("complex() second arg can't be a string"); } imag2 = Converter.ConvertToComplex(imag); } if (real != null) { if (real is string) { real2 = LiteralParser.ParseComplex((string)real); } else if (real is Extensible <string> ) { real2 = LiteralParser.ParseComplex(((Extensible <string>)real).Value); } else if (real is Complex) { if (imag == null && cls == TypeCache.Complex) { return(real); } else { real2 = (Complex)real; } } else { real2 = Converter.ConvertToComplex(real); } } double real3 = real2.Real - imag2.Imaginary(); double imag3 = real2.Imaginary() + imag2.Real; if (cls == TypeCache.Complex) { return(new Complex(real3, imag3)); } else { return(cls.CreateInstance(context, real3, imag3)); } }
public static Complex64 Negate(Complex64 x) { return(-x); }
public static Complex64 Asin(Complex64 z) { if (z.imag == 0 && z.real < 0) { return -Asin(new Complex64(-z.real, 0)); } if (z.imag > 0) { return -Asin(-z); } return -i * Log(z * i + Sqrt(1 - (z * z))); }
public static Complex64 Cos(Complex64 z) { Complex64 z1 = Exp(new Complex64(-z.imag, z.real)); Complex64 z2 = Exp(new Complex64(z.imag, -z.real)); return new Complex64(0.5 * (z1.real + z2.real), 0.5 * (z1.imag + z2.imag)); }
public static Complex64 Pow(Complex64 baseNumber, Complex64 index) { if (baseNumber == 0) { // this is really non-sensical, but the behavior is defined in the spec, so try follow it at least. if (index == 0) { return 1; } return 0; } return Exp(index * Log(baseNumber)); }
public static Complex64 Exp(Complex64 z) { double value = System.Math.Exp(z.real); return new Complex64( value * System.Math.Cos(z.imag), value * System.Math.Sin(z.imag)); }
private void WriteComplex(Complex val) { _bytes.Add((byte)'x'); WriteDoubleString(val.Real); WriteDoubleString(val.Imaginary()); }
public static Complex64 Acos(Complex64 z) { return -i * Log(z + i * Sqrt(1 - Pow(z, 2))); }
public static double Getreal(Complex self) { return(self.Real); }
private void WriteComplex (Complex val) { _bytes.Add ((byte)'x'); WriteDoubleString (val.Real); WriteDoubleString (val.Imaginary ()); }
public static double Getimag(Complex self) { return(self.Imaginary()); }
public static Complex64 Subtract(Complex64 x, Complex64 y) { return x - y; }
public static Complex Add(Complex x, Complex y) { return(x + y); }
public static Complex64 Plus(Complex64 x) { return +x; }
public static Complex Subtract(Complex x, Complex y) { return(x - y); }
public static Complex64 Subtract(Complex64 x, Complex64 y) { return(x - y); }
public static Complex Multiply(Complex x, Complex y) { return(x * y); }
public static Complex64 Divide(Complex64 x, Complex64 y) { return(x / y); }
public static Complex TrueDivide(Complex x, Complex y) { return(Divide(x, y)); }
public static Complex64 Plus(Complex64 x) { return(+x); }
public static Complex Power(Complex x, Complex y) { return(op_Power(x, y)); }
public static Complex64 Mod(Complex64 x, Complex64 y) { return x % y; }
public static Complex Mod(CodeContext context, Complex x, Complex y) { Complex quotient = FloorDivide(context, x, y); return(x - (quotient * y)); }
public static Complex64 Sinh(Complex64 z) { Complex64 z1 = Exp(z); Complex64 z2 = Exp(new Complex64(-z.real, -z.imag)); return new Complex64(0.5 * (z1.real - z2.real), 0.5 * (z1.imag - z2.imag)); }
public static PythonTuple DivMod(CodeContext context, Complex x, Complex y) { Complex quotient = FloorDivide(context, x, y); return(PythonTuple.MakeTuple(quotient, x - (quotient * y))); }
public static Complex64 Tanh(Complex64 z) { return Sinh(z) / Cosh(z); }
public static bool __nonzero__(Complex x) { return(!x.IsZero()); }
public static Complex64 Log(Complex64 z) { return new Complex64(System.Math.Log(z.Modulus), z.Argument); }
public static Complex conjugate(Complex x) { return(x.Conjugate()); }
public static Complex64 Sqrt(Complex64 z) { return Polar(System.Math.Sqrt(z.Modulus), z.Argument / 2); }
public static object __pos__(Complex x) { return(x); }
public static Complex64 Asin(Complex64 z) { return -i * Log(z * i + Sqrt(1 - Pow(z, 2))); }
private static bool IsInfinity(Complex64 num) { return double.IsInfinity(num.Real) || double.IsInfinity(num.Imag); }
public static Complex64 Atanh(Complex64 z) { throw new NotImplementedException(); }
private static bool IsNaN(Complex64 num) { return double.IsNaN(num.Real) || double.IsNaN(num.Imag); }
StoreTyped(Complex64 value) { IntPtr ptr = this.allocator.Alloc((uint)Marshal.SizeOf(typeof(PyComplexObject))); CPyMarshal.WriteIntField(ptr, typeof(PyComplexObject), "ob_refcnt", 1); CPyMarshal.WritePtrField(ptr, typeof(PyComplexObject), "ob_type", this.PyComplex_Type); IntPtr cpxptr = CPyMarshal.GetField(ptr, typeof(PyComplexObject), "cval"); CPyMarshal.WriteDoubleField(cpxptr, typeof(Py_complex), "real", value.Real); CPyMarshal.WriteDoubleField(cpxptr, typeof(Py_complex), "imag", value.Imag); this.map.Associate(ptr, value); return ptr; }
private static double GetImag(Complex64 num) { return num.Imag; }
public static Complex64 Add(Complex64 x, Complex64 y) { return x + y; }
private static double GetAngle(Complex64 num) { if (IsNaN(num)) { return double.NaN; } if (double.IsPositiveInfinity(num.Real)) { if (double.IsPositiveInfinity(num.Imag)) { return Math.PI * 0.25; } else if (double.IsNegativeInfinity(num.Imag)) { return Math.PI * -0.25; } else { return 0.0; } } if (double.IsNegativeInfinity(num.Real)) { if (double.IsPositiveInfinity(num.Imag)) { return Math.PI * 0.75; } else if (double.IsNegativeInfinity(num.Imag)) { return Math.PI * -0.75; } else { return DoubleOps.Sign(num.Imag) * Math.PI; } } if (num.Real == 0.0) { if (num.Imag != 0.0) { return Math.PI * 0.5 * Math.Sign(num.Imag); } else { return (DoubleOps.IsPositiveZero(num.Real) ? 0.0 : Math.PI) * DoubleOps.Sign(GetImag(num)); } } return Math.Atan2(num.Imag, num.Real); }
public static Complex64 Multiply(Complex64 x, Complex64 y) { return x * y; }
public static Complex64 Mod(Complex64 x, Complex64 y) { return(x % y); }
public static Complex64 Negate(Complex64 x) { return -x; }
public static Complex64 Add(Complex64 x, Complex64 y) { return(x + y); }
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 = One; 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 ? One : Zero; } 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)); } }
public static Complex64 Sqrt(Complex64 z) { return(Polar(System.Math.Sqrt(z.Modulus), z.Argument / 2)); }