public static object FloorDivide(BigInteger x, object other) { if (other is int) { return(Divide(x, (int)other)); } if (other is Complex64) { Complex64 y = (Complex64)other; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.FloorDivide(Complex64.MakeReal(x), y)); } if (other is double) { return(FloatOps.FloorDivide(x, (double)other)); } if (other is bool) { return(Divide(x, (bool)other ? 1 : 0)); } if (other is long) { return(Divide(x, (long)other)); } if (other is BigInteger) { return(Divide(x, (BigInteger)other)); } if (other is ExtensibleInt) { return(Divide(x, ((ExtensibleInt)other).value)); } if (other is ExtensibleComplex) { Complex64 y = ((ExtensibleComplex)other).value; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.FloorDivide(Complex64.MakeReal(x), y)); } if (other is byte) { return(Divide(x, (int)((byte)other))); } if (other is ExtensibleFloat) { return(FloatOps.FloorDivide(x, ((ExtensibleFloat)other).value)); } return(Ops.NotImplemented); }
public static object ReverseMod(BigInteger x, object other) { if (other is int) { return(IntOps.Mod((int)other, x)); } if (other is Complex64) { Complex64 y = (Complex64)other; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.Mod(y, Complex64.MakeReal(x))); } if (other is double) { return(FloatOps.Mod((double)other, x)); } if (other is bool) { return(Mod((bool)other ? 1 : 0, x)); } if (other is long) { return(Mod((long)other, x)); } if (other is BigInteger) { return(Mod((BigInteger)other, x)); } if (other is ExtensibleInt) { return(Mod(((ExtensibleInt)other).value, x)); } if (other is ExtensibleComplex) { Complex64 y = ((ExtensibleComplex)other).value; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.Mod(y, Complex64.MakeReal(x))); } if (other is byte) { return(IntOps.Mod((int)((byte)other), x)); } if (other is ExtensibleFloat) { return(FloatOps.Mod(((ExtensibleFloat)other).value, x)); } return(Ops.NotImplemented); }
public static object Compare(long x, object other) { if (other is int) { return(CompareWorker(x, (long)(int)other)); } else if (other is long) { return(CompareWorker(x, (long)other)); } else if (other is double) { return(CompareWorker(x, (double)other)); } else if (other is BigInteger) { return(-(int)LongOps.Compare((BigInteger)other, x)); } else if (other is Complex64) { return(ComplexOps.TrueCompare(new Complex64((double)x, 0), (Complex64)other)); } else if (other is float) { return(CompareWorker(x, (double)(float)other)); } else if (other is bool) { return(CompareWorker(x, ((bool)other) ? 1L : 0L)); } else if (other is decimal) { return(CompareWorker(x, (decimal)other)); } else if (other is ulong) { return(CompareWorker(x, (ulong)other)); } Conversion conversion; double y = Converter.TryConvertToInt64(other, out conversion); if (conversion != Conversion.None) { CompareWorker(x, y); } return(Ops.NotImplemented); }
public static object Subtract(double x, object other) { if (other is double) { return(x - ((double)other)); } if (other is int) { return(x - ((int)other)); } if (other is Complex64) { return(ComplexOps.Subtract(Complex64.MakeReal(x), (Complex64)other)); } if (other is BigInteger) { return(x - ((BigInteger)other)); } if (other is float) { return(x - ((float)other)); } if (other is ExtensibleFloat) { return(x - ((ExtensibleFloat)other).value); } if (other is string) { return(Ops.NotImplemented); } if (other is IConvertible) { double y = ((IConvertible)other).ToDouble(null); return(x - y); } if (other is long) { return(x - ((long)other)); } if (other is ExtensibleInt) { return(x - ((ExtensibleInt)other).value); } if (other is ExtensibleComplex) { return(ComplexOps.Subtract(Complex64.MakeReal(x), ((ExtensibleComplex)other).value)); } return(Ops.NotImplemented); }
public static object Power(double x, object other) { if (other is int) { return(Power(x, ((int)other))); } if (other is long) { return(Power(x, ((long)other))); } if (other is Complex64) { return(ComplexOps.Power(x, ((Complex64)other))); } if (other is double) { return(Power(x, ((double)other))); } if (other is BigInteger) { return(Power(x, ((BigInteger)other))); } if (other is bool) { return(Power(x, (bool)other ? 1 : 0)); } if (other is float) { return(Power(x, ((float)other))); } if (other is ExtensibleFloat) { return(Power(x, ((ExtensibleFloat)other).value)); } if (other is ExtensibleInt) { return(Power(x, ((ExtensibleInt)other).value)); } if (other is ExtensibleComplex) { return(ComplexOps.Power(x, ((ExtensibleComplex)other).value)); } if (other is byte) { return(Power(x, (int)((byte)other))); } return(Ops.NotImplemented); }
public static object TrueDivide(double x, object other) { if (other is double) { return(TrueDivide(x, ((double)other))); } if (other is int) { return(TrueDivide(x, ((int)other))); } if (other is Complex64) { return(ComplexOps.TrueDivide(Complex64.MakeReal(x), (Complex64)other)); } if (other is BigInteger) { return(TrueDivide(x, ((BigInteger)other))); } if (other is bool) { return(TrueDivide(x, (bool)other ? 1.0 : 0.0)); } if (other is float) { return(TrueDivide(x, ((float)other))); } if (other is ExtensibleFloat) { return(TrueDivide(x, ((ExtensibleFloat)other).value)); } if (other is long) { return(TrueDivide(x, ((long)other))); } if (other is ExtensibleComplex) { return(ComplexOps.TrueDivide(Complex64.MakeReal(x), ((ExtensibleComplex)other).value)); } if (other is ExtensibleInt) { return(TrueDivide(x, ((ExtensibleInt)other).value)); } if (other is byte) { return(TrueDivide(x, (int)((byte)other))); } return(Ops.NotImplemented); }
public static object Mod(Complex64 x, object other) { object rawQuotient = ComplexOps.FloorDivide(x, other); if (rawQuotient == Ops.NotImplemented) { return(rawQuotient); } if (rawQuotient is Complex64) { Complex64 complexQuotient = (Complex64)rawQuotient; Complex64 product = (Complex64)ComplexOps.Multiply(complexQuotient, other); return(ComplexOps.Subtract(x, product)); } else { return(Ops.NotImplemented); } }
public static object Compare(double self, object other) { if (other == null) { return(1); } Conversion conv; double val = Converter.TryConvertToDouble(other, out conv); if (conv == Conversion.None) { object res = Ops.GetDynamicType(other).Coerce(other, self); if (res != Ops.NotImplemented && !(res is OldInstance)) { return(Ops.Compare(((Tuple)res)[1], ((Tuple)res)[0])); } Complex64 c64 = Converter.TryConvertToComplex64(other, out conv); if (conv != Conversion.None) { return(ComplexOps.TrueCompare(c64, new Complex64(self)) * -1); } return(Ops.NotImplemented); } if (val == self) { return(0); } if (self < val) { return(-1); } return(1); }
public static object Mod(double x, object other) { if (other is int) { int y = (int)other; if (y == 0) { throw Ops.ZeroDivisionError(); } return(Modulo(x, y)); } if (other is long) { long y = (long)other; if (y == 0) { throw Ops.ZeroDivisionError(); } return(Modulo(x, y)); } if (other is Complex64) { Complex64 y = (Complex64)other; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.Mod(Complex64.MakeReal(x), y)); } if (other is double) { double y = (double)other; if (y == 0) { throw Ops.ZeroDivisionError(); } return(Modulo(x, y)); } if (other is BigInteger) { BigInteger y = (BigInteger)other; if (y == BigInteger.Zero) { throw Ops.ZeroDivisionError(); } return(Modulo(x, y)); } if (other is ExtensibleFloat) { ExtensibleFloat y = (ExtensibleFloat)other; if (y.value == 0) { throw Ops.ZeroDivisionError(); } return(Modulo(x, y.value)); } if (other is ExtensibleInt) { int y = ((ExtensibleInt)other).value; if (y == 0) { throw Ops.ZeroDivisionError(); } return(Modulo(x, y)); } if (other is ExtensibleComplex) { Complex64 y = ((ExtensibleComplex)other).value; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.Mod(Complex64.MakeReal(x), y)); } if (other is IConvertible) { double y = ((IConvertible)other).ToDouble(null); if (y == 0) { throw Ops.ZeroDivisionError(); } return(Modulo(x, y)); } return(Ops.NotImplemented); }
public static object Mod(long x, object other) { if (other is int) { int y = (int)other; try { return(Ops.Long2Object(Mod(x, y))); } catch (OverflowException) { return(BigInteger.Create(x) % y); } } else if (other is BigInteger) { return(LongOps.Mod(BigInteger.Create(x), (BigInteger)other)); } else if (other is double) { return(FloatOps.Mod(x, (double)other)); } else if (other is Complex64) { return(ComplexOps.Mod(Complex64.MakeReal(x), (Complex64)other)); } else if (other is bool) { int y = (bool)other ? 1 : 0; try { return(Ops.Long2Object(Mod(x, y))); } catch (OverflowException) { return(BigInteger.Create(x) % y); } } else if (other is long) { long y = (long)other; try { return(Mod(x, y)); } catch (OverflowException) { return(BigInteger.Create(x) % y); } } else if (other is float) { return(FloatOps.Mod(x, (float)other)); } else if (other is ExtensibleInt) { int y = ((ExtensibleInt)other).value; try { return(Ops.Long2Object(Mod(x, y))); } catch (OverflowException) { return(BigInteger.Create(x) % y); } } else if (other is ExtensibleFloat) { return(FloatOps.Mod(x, ((ExtensibleFloat)other).value)); } else if (other is ExtensibleComplex) { return(ComplexOps.Mod(Complex64.MakeReal(x), ((ExtensibleComplex)other).value)); } else if (other is byte) { int y = (int)((byte)other); try { return(Ops.Long2Object(Mod(x, y))); } catch (OverflowException) { return(BigInteger.Create(x) % y); } } return(Ops.NotImplemented); }
public static object Power(int x, object other) { if (other is int) { return(Power(x, (int)other)); } else if (other is BigInteger) { BigInteger lexp = (BigInteger)other; int iexp; if (lexp.AsInt32(out iexp)) { return(Power(x, iexp)); } else { if (x == 0) { return(0); } if (x == 1) { return(1); } throw Ops.ValueError("number too big"); } } else if (other is long) { long lexp = (long)other; int iexp = (int)lexp; if (lexp == iexp) { return(Power(x, iexp)); } else { if (x == 0) { return(0); } if (x == 1) { return(1); } throw Ops.ValueError("Number too big"); } } else if (other is double) { return(FloatOps.Power(x, (double)other)); } else if (other is bool) { return(Power(x, (bool)other ? 1 : 0)); } else if (other is float) { return(FloatOps.Power(x, (float)other)); } else if (other is Complex64) { return(ComplexOps.Power(x, other)); } else if (other is byte) { return(Power(x, (int)(byte)other)); } else if (other is ExtensibleInt) { return(Power(x, ((ExtensibleInt)other).value)); } else if (other is ExtensibleFloat) { return(FloatOps.Power(x, ((ExtensibleFloat)other).value)); } else if (other is ExtensibleComplex) { return(ComplexOps.Power(x, ((ExtensibleComplex)other).value)); } return(Ops.NotImplemented); }
private static object TrueDivide(int x, Complex64 y) { return(ComplexOps.TrueDivide(Complex64.MakeReal(x), y)); }
public static object Mod(int x, object other) { if (other is int) { int y = (int)other; try { return(Ops.Int2Object(Mod(x, y))); } catch (OverflowException) { return(LongOps.Mod(BigInteger.Create(x), y)); } } else if (other is BigInteger) { return(LongOps.Mod(BigInteger.Create(x), (BigInteger)other)); } else if (other is double) { return(FloatOps.Mod(x, (double)other)); } else if (other is Complex64) { Complex64 y = (Complex64)other; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.Mod(Complex64.MakeReal(x), y)); } else if (other is bool) { bool b = (bool)other; return(x % (b ? 1 : 0)); } else if (other is long) { long y = (long)other; try { return(Mod(x, y)); } catch (OverflowException) { return(LongOps.Mod(BigInteger.Create(x), y)); } } else if (other is float) { return(FloatOps.Mod(x, (float)other)); } else if (other is byte) { return(Ops.Int2Object(Mod(x, (int)((byte)other)))); } else if (other is ExtensibleInt) { int y = ((ExtensibleInt)other).value; try { return(Ops.Int2Object(Mod(x, y))); } catch (OverflowException) { return(LongOps.Mod(BigInteger.Create(x), y)); } } else if (other is ExtensibleFloat) { return(FloatOps.Mod(x, ((ExtensibleFloat)other).value)); } else if (other is ExtensibleComplex) { Complex64 y = ((ExtensibleComplex)other).value; if (y.IsZero) { throw Ops.ZeroDivisionError(); } return(ComplexOps.Mod(Complex64.MakeReal(x), y)); } return(Ops.NotImplemented); }
public static object Add(int x, object other) { if (other is int) { int y = (int)other; try { return(Ops.Int2Object(checked (x + y))); } catch (OverflowException) { return(BigInteger.Create(x) + y); } } else if (other is BigInteger) { return(BigInteger.Create(x) + (BigInteger)other); } else if (other is double) { return(x + (double)other); } else if (other is Complex64) { return(ComplexOps.Add(Complex64.MakeReal(x), other)); } else if (other is bool) { bool b = (bool)other; return(x + (b ? 1 : 0)); } else if (other is long) { long y = (long)other; try { return(checked (x + y)); } catch (OverflowException) { return(BigInteger.Create(x) + y); } } else if (other is float) { return(x + (float)other); } else if (other is byte) { return(x + (byte)other); } else if (other is ExtensibleInt) { int y = ((ExtensibleInt)other).value; try { return(Ops.Int2Object(checked (x + y))); } catch (OverflowException) { return(BigInteger.Create(x) + y); } } else if (other is ExtensibleFloat) { return(x + ((ExtensibleFloat)other).value); } else if (other is ExtensibleComplex) { return(ComplexOps.Add(Complex64.MakeReal(x), (ExtensibleComplex)other)); } else if (other is byte) { int y = (byte)other; try { return(Ops.Int2Object(checked (x + y))); } catch (OverflowException) { return(BigInteger.Create(x) + y); } } return(Ops.NotImplemented); }