Пример #1
0
 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)
         );
     }
 }
Пример #2
0
 public static Complex64 Atan(Complex64 z)
 {
     return(i / 2 * Log((i + z) / (i - z)));
 }
Пример #3
0
 public static Complex64 Divide(Complex64 x, Complex64 y) {
     return x / y;
 }
Пример #4
0
 public static Complex64 Pow(this Complex64 self, Complex64 power) {
     return self.Power(power);
 }
Пример #5
0
 public static Complex64 Atan(Complex64 z)
 {
   return i/2 * Log((i + z)/(i - z));
 }
Пример #6
0
 public static Complex64 Pow(Complex64 baseNumber, Complex64 index)
 {
   return Exp(index * Log(baseNumber));
 }
Пример #7
0
 public static Complex64 Tan(Complex64 z)
 {
   return Sin(z) / Cos(z);
 }
Пример #8
0
 public static bool LessThan(Complex x, Complex y)
 {
     throw PythonOps.TypeError("complex is not an ordered type");
 }
Пример #9
0
 public static bool GreaterThanOrEqual(Complex x, Complex y)
 {
     throw PythonOps.TypeError("complex is not an ordered type");
 }
Пример #10
0
 public static int __int__(Complex self)
 {
     throw PythonOps.TypeError(" can't convert complex to int; use int(abs(z))");
 }
Пример #11
0
 public static BigInteger __long__(Complex self)
 {
     throw PythonOps.TypeError("can't convert complex to long; use long(abs(z))");
 }
Пример #12
0
 // 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)");
 }
Пример #13
0
 public static string __repr__(CodeContext /*!*/ context, Complex x)
 {
     return(__str__(context, x));
 }
Пример #14
0
 public static Complex64 Atanh(Complex64 z)
 {
     throw new NotImplementedException();
 }
Пример #15
0
 public static Complex64 Multiply(Complex64 x, Complex64 y)
 {
     return(x * y);
 }
Пример #16
0
        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));
            }
        }
Пример #17
0
 public static Complex64 Negate(Complex64 x)
 {
     return(-x);
 }
Пример #18
0
 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)));
 }
Пример #19
0
        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));
        }
Пример #20
0
 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));
 }
Пример #21
0
        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));
        }
Пример #22
0
 private void WriteComplex(Complex val)
 {
     _bytes.Add((byte)'x');
     WriteDoubleString(val.Real);
     WriteDoubleString(val.Imaginary());
 }
Пример #23
0
 public static Complex64 Acos(Complex64 z)
 {
   return -i * Log(z + i * Sqrt(1 - Pow(z, 2)));
 }
Пример #24
0
 public static double Getreal(Complex self)
 {
     return(self.Real);
 }
Пример #25
0
 private void WriteComplex (Complex val) {
     _bytes.Add ((byte)'x');
     WriteDoubleString (val.Real);
     WriteDoubleString (val.Imaginary ());
 }
Пример #26
0
 public static double Getimag(Complex self)
 {
     return(self.Imaginary());
 }
Пример #27
0
 public static Complex64 Subtract(Complex64 x, Complex64 y) {
     return x - y;
 }
Пример #28
0
 public static Complex Add(Complex x, Complex y)
 {
     return(x + y);
 }
Пример #29
0
 public static Complex64 Plus(Complex64 x) {
     return +x;
 }
Пример #30
0
 public static Complex Subtract(Complex x, Complex y)
 {
     return(x - y);
 }
Пример #31
0
 public static Complex64 Subtract(Complex64 x, Complex64 y)
 {
     return(x - y);
 }
Пример #32
0
 public static Complex Multiply(Complex x, Complex y)
 {
     return(x * y);
 }
Пример #33
0
 public static Complex64 Divide(Complex64 x, Complex64 y)
 {
     return(x / y);
 }
Пример #34
0
 public static Complex TrueDivide(Complex x, Complex y)
 {
     return(Divide(x, y));
 }
Пример #35
0
 public static Complex64 Plus(Complex64 x)
 {
     return(+x);
 }
Пример #36
0
 public static Complex Power(Complex x, Complex y)
 {
     return(op_Power(x, y));
 }
Пример #37
0
 public static Complex64 Mod(Complex64 x, Complex64 y) {
     return x % y;
 }
Пример #38
0
        public static Complex Mod(CodeContext context, Complex x, Complex y)
        {
            Complex quotient = FloorDivide(context, x, y);

            return(x - (quotient * y));
        }
Пример #39
0
        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));
        }
Пример #40
0
        public static PythonTuple DivMod(CodeContext context, Complex x, Complex y)
        {
            Complex quotient = FloorDivide(context, x, y);

            return(PythonTuple.MakeTuple(quotient, x - (quotient * y)));
        }
Пример #41
0
 public static Complex64 Tanh(Complex64 z)
 {
   return Sinh(z) / Cosh(z);
 }
Пример #42
0
 public static bool __nonzero__(Complex x)
 {
     return(!x.IsZero());
 }
Пример #43
0
 public static Complex64 Log(Complex64 z)
 {
   return new Complex64(System.Math.Log(z.Modulus), z.Argument);
 }
Пример #44
0
 public static Complex conjugate(Complex x)
 {
     return(x.Conjugate());
 }
Пример #45
0
 public static Complex64 Sqrt(Complex64 z)
 {
   return Polar(System.Math.Sqrt(z.Modulus), z.Argument / 2);
 }
Пример #46
0
 public static object __pos__(Complex x)
 {
     return(x);
 }
Пример #47
0
 public static Complex64 Asin(Complex64 z)
 {
   return -i * Log(z * i + Sqrt(1 - Pow(z, 2)));
 }
Пример #48
0
 private static bool IsInfinity(Complex64 num) {
     return double.IsInfinity(num.Real) || double.IsInfinity(num.Imag);
 }
Пример #49
0
 public static Complex64 Atanh(Complex64 z)
 {
   throw new NotImplementedException();
 }
Пример #50
0
 private static bool IsNaN(Complex64 num) {
     return double.IsNaN(num.Real) || double.IsNaN(num.Imag);
 }
Пример #51
0
 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;
 }
Пример #52
0
 private static double GetImag(Complex64 num) {
     return num.Imag;
 }
Пример #53
0
 public static Complex64 Add(Complex64 x, Complex64 y) {
     return x + y;
 }
Пример #54
0
        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);
        }
Пример #55
0
 public static Complex64 Multiply(Complex64 x, Complex64 y) {
     return x * y;
 }
Пример #56
0
 public static Complex64 Mod(Complex64 x, Complex64 y)
 {
     return(x % y);
 }
Пример #57
0
 public static Complex64 Negate(Complex64 x) {
     return -x;
 }
Пример #58
0
 public static Complex64 Add(Complex64 x, Complex64 y)
 {
     return(x + y);
 }
Пример #59
0
        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));
            }
        }
Пример #60
0
 public static Complex64 Sqrt(Complex64 z)
 {
     return(Polar(System.Math.Sqrt(z.Modulus), z.Argument / 2));
 }