public static object Multiply(Complex64 x, object other)
        {
            BigInteger bi;
            ExtensibleComplex xc;
            INumber num;

            if (other is int) {
                return x * (int)other;
            } else if (other is Complex64) {
                return x * (Complex64)other;
            } else if (other is double) {
                return x * (double)other;
            } else if ((object)(bi = other as BigInteger) != null) {
                return x * bi;
            } else if (other is long) {
                return x * (long)other;
            } else if ((object)(xc = other as ExtensibleComplex) != null) {
                return x * xc.value;
            } else if ((object)(num = other as INumber) != null) {
                return num.ReverseMultiply(x);
            } else if (other is string) {
                return Ops.NotImplemented;
            } else if (other is IConvertible) {
                double y = ((IConvertible)other).ToDouble(null);
                return x * y;
            }
            return Ops.NotImplemented;
        }
Beispiel #2
0
 void WriteComplex(Complex64 val)
 {
     bytes.Add((byte)'x');
     WriteDoubleString(val.real);
     WriteDoubleString(val.imag);
 }
        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 = new Complex64(1.0);
                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 ? Complex64.MakeReal(1.0) : Complex64.MakeReal(0.0);
            }
            else
            {
                double a = real;
                double b = imag;
                double powers = a * a + b * b;
                double arg = Math.Atan2(b, a);
                double mul = Math.Pow(powers, c / 2) * Math.Pow(Math.E, -d * arg);
                double common = c * arg + .5 * d * Math.Log(powers, Math.E);

                return new Complex64(mul * Math.Cos(common), mul * Math.Sin(common));
            }
        }
 public static Complex64 Subtract(Complex64 x, Complex64 y)
 {
     return x - y;
 }
 public static Complex64 Negate(Complex64 x)
 {
     return -x;
 }
 public static Complex64 Multiply(Complex64 x, Complex64 y)
 {
     return x * y;
 }
Beispiel #7
0
 public static Complex64 Add(Complex64 x, Complex64 y)
 {
     return(x + y);
 }
        public static object Power(Complex64 x, object other)
        {
            BigInteger bi;
            INumber num;
            ExtensibleComplex xc;

            if (other is int) return Power(x, (Complex64)((int)other));
            if (other is Complex64) return Power(x, (Complex64)other);
            if (other is double) return Power(x, (Complex64)((double)other));
            if ((object)(bi = other as BigInteger) != null) return Power(x, (Complex64)bi);
            if (other is bool) return Power(x, (Complex64)((bool)other ? 1 : 0));
            if (other is long) return Power(x, (Complex64)((long)other));
            if ((object)(xc = other as ExtensibleComplex) != null) return Power(x, xc.value);
            if ((object)(num = other as INumber) != null) return num.ReversePower(x);
            if (other is byte) return Power(x, (Complex64)(int)((byte)other));
            return Ops.NotImplemented;
        }
 public static Complex64 Add(Complex64 x, Complex64 y)
 {
     return x + y;
 }
Beispiel #10
0
 public static Complex64 Negate(Complex64 x)
 {
     return(-x);
 }
Beispiel #11
0
 public static Complex64 Modulus(Complex64 x, Complex64 y)
 {
     return(x % y);
 }
Beispiel #12
0
 public static Complex64 Divide(Complex64 x, Complex64 y)
 {
     return(x / y);
 }
Beispiel #13
0
 public static Complex64 Multiply(Complex64 x, Complex64 y)
 {
     return(x * y);
 }
Beispiel #14
0
 public static Complex64 Subtract(Complex64 x, Complex64 y)
 {
     return(x - y);
 }
        public static object ReverseSubtract(Complex64 x, object other)
        {
            BigInteger bi;
            ExtensibleComplex xc;
            INumber num;

            if (other is int) {
                return (int)other - x;
            } else if (other is Complex64) {
                return (Complex64)other - x;
            } else if (other is double) {
                return (double)other - x;
            } else if ((object)(bi = other as BigInteger) != null) {
                return bi - x;
            } else if (other is long) {
                return (long)other - x;
            } else if ((object)(xc = other as ExtensibleComplex) != null) {
                return xc.value - x;
            } else if ((object)(num = other as INumber) != null) {
                return num.Subtract(x);
            } else if (other is string) {
                return Ops.NotImplemented;
            } else if (other is IConvertible) {
                double y = ((IConvertible)other).ToDouble(null);
                return y - x;
            }
            return Ops.NotImplemented;
        }
 public static Complex64 Divide(Complex64 x, Complex64 y)
 {
     return x / y;
 }
 public static Complex64 Modulus(Complex64 x, Complex64 y)
 {
     return x % y;
 }
 /// <summary>
 /// Conversion routine TryConvertToComplex64 - converts object to Complex64
 /// Try to avoid using this method, the goal is to ultimately remove it!
 /// </summary>
 internal static bool TryConvertToComplex64(object value, out Complex64 result)
 {
     try {
         result = ConvertToComplex64(value);
         return true;
     } catch {
         result = default(Complex64);
         return false;
     }
 }
Beispiel #19
0
 private static object TrueDivide(int x, Complex64 y)
 {
     return ComplexOps.TrueDivide(Complex64.MakeReal(x), y);
 }