コード例 #1
0
        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;
        }
コード例 #2
0
 void WriteComplex(Complex64 val)
 {
     bytes.Add((byte)'x');
     WriteDoubleString(val.real);
     WriteDoubleString(val.imag);
 }
コード例 #3
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 = 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));
            }
        }
コード例 #4
0
 public static Complex64 Subtract(Complex64 x, Complex64 y)
 {
     return x - y;
 }
コード例 #5
0
 public static Complex64 Negate(Complex64 x)
 {
     return -x;
 }
コード例 #6
0
 public static Complex64 Multiply(Complex64 x, Complex64 y)
 {
     return x * y;
 }
コード例 #7
0
 public static Complex64 Add(Complex64 x, Complex64 y)
 {
     return(x + y);
 }
コード例 #8
0
        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;
        }
コード例 #9
0
 public static Complex64 Add(Complex64 x, Complex64 y)
 {
     return x + y;
 }
コード例 #10
0
 public static Complex64 Negate(Complex64 x)
 {
     return(-x);
 }
コード例 #11
0
 public static Complex64 Modulus(Complex64 x, Complex64 y)
 {
     return(x % y);
 }
コード例 #12
0
 public static Complex64 Divide(Complex64 x, Complex64 y)
 {
     return(x / y);
 }
コード例 #13
0
 public static Complex64 Multiply(Complex64 x, Complex64 y)
 {
     return(x * y);
 }
コード例 #14
0
 public static Complex64 Subtract(Complex64 x, Complex64 y)
 {
     return(x - y);
 }
コード例 #15
0
        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;
        }
コード例 #16
0
 public static Complex64 Divide(Complex64 x, Complex64 y)
 {
     return x / y;
 }
コード例 #17
0
 public static Complex64 Modulus(Complex64 x, Complex64 y)
 {
     return x % y;
 }
コード例 #18
0
 /// <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;
     }
 }
コード例 #19
0
ファイル: IntOps.cs プロジェクト: FabioNascimento/DICommander
 private static object TrueDivide(int x, Complex64 y)
 {
     return ComplexOps.TrueDivide(Complex64.MakeReal(x), y);
 }