public static object ReverseFloorDivide(BigInteger x, object other)
 {
     if (other is int)
     {
         return(IntOps.Divide((int)other, x));
     }
     if (other is Complex64)
     {
         Complex64 y = (Complex64)other;
         if (y.IsZero)
         {
             throw Ops.ZeroDivisionError();
         }
         return(ComplexOps.Divide(y, Complex64.MakeReal(x)));
     }
     if (other is double)
     {
         return(FloatOps.FloorDivide((double)other, x));
     }
     if (other is bool)
     {
         return(Divide((bool)other ? 1 : 0, x));
     }
     if (other is long)
     {
         return(Divide((long)other, x));
     }
     if (other is BigInteger)
     {
         return(Divide((BigInteger)other, x));
     }
     if (other is ExtensibleInt)
     {
         return(Divide(((ExtensibleInt)other).value, x));
     }
     if (other is ExtensibleComplex)
     {
         Complex64 y = ((ExtensibleComplex)other).value;
         if (y.IsZero)
         {
             throw Ops.ZeroDivisionError();
         }
         return(ComplexOps.FloorDivide(y, Complex64.MakeReal(x)));
     }
     if (other is byte)
     {
         return(IntOps.Divide((int)((byte)other), x));
     }
     if (other is ExtensibleFloat)
     {
         return(FloatOps.FloorDivide(((ExtensibleFloat)other).value, x));
     }
     return(Ops.NotImplemented);
 }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public static object FloorDivide(double x, object other)
        {
            if (other is int)
            {
                int y = (int)other;
                if (y == 0)
                {
                    throw Ops.ZeroDivisionError();
                }
                return(Math.Floor(x / y));
            }
            if (other is long)
            {
                long y = (long)other;
                if (y == 0)
                {
                    throw Ops.ZeroDivisionError();
                }
                return(Math.Floor(x / y));
            }
            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)
            {
                double y = (double)other;
                if (y == 0)
                {
                    throw Ops.ZeroDivisionError();
                }
                return(Math.Floor(x / y));
            }
            if (other is BigInteger)
            {
                BigInteger y = (BigInteger)other;
                if (y == BigInteger.Zero)
                {
                    throw Ops.ZeroDivisionError();
                }
                return(Math.Floor(x / y));
            }
            if (other is ExtensibleFloat)
            {
                ExtensibleFloat y = (ExtensibleFloat)other;
                if (y.value == 0)
                {
                    throw Ops.ZeroDivisionError();
                }
                return(Math.Floor(x / y.value));
            }
            if (other is ExtensibleInt)
            {
                int y = ((ExtensibleInt)other).value;
                if (y == 0)
                {
                    throw Ops.ZeroDivisionError();
                }
                return(Math.Floor(x / y));
            }
            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 IConvertible)
            {
                double y = ((IConvertible)other).ToDouble(null);
                if (y == 0)
                {
                    throw Ops.ZeroDivisionError();
                }
                return(Math.Floor(x / y));
            }
            return(Ops.NotImplemented);
        }
        public static object FloorDivide(long x, object other)
        {
            if (other is int)
            {
                int y = (int)other;
                try {
                    return(Ops.Long2Object(Divide(x, y)));
                } catch (OverflowException) {
                    return(BigInteger.Create(x) / y);
                }
            }
            else if (other is BigInteger)
            {
                return(LongOps.FloorDivide(BigInteger.Create(x), (BigInteger)other));
            }
            else if (other is double)
            {
                return(FloatOps.FloorDivide(x, (double)other));
            }
            else if (other is Complex64)
            {
                return(ComplexOps.FloorDivide(Complex64.MakeReal(x), (Complex64)other));
            }
            else if (other is bool)
            {
                int y = (bool)other ? 1 : 0;
                try {
                    return(Ops.Long2Object(Divide(x, y)));
                } catch (OverflowException) {
                    return(BigInteger.Create(x) / y);
                }
            }
            else if (other is long)
            {
                long y = (long)other;
                try {
                    return(Divide(x, y));
                } catch (OverflowException) {
                    return(BigInteger.Create(x) / y);
                }
            }
            else if (other is float)
            {
                return(FloatOps.FloorDivide(x, (float)other));
            }
            else if (other is ExtensibleInt)
            {
                int y = ((ExtensibleInt)other).value;
                try {
                    return(Ops.Long2Object(Divide(x, y)));
                } catch (OverflowException) {
                    return(BigInteger.Create(x) / y);
                }
            }
            else if (other is ExtensibleFloat)
            {
                return(FloatOps.FloorDivide(x, ((ExtensibleFloat)other).value));
            }
            else if (other is ExtensibleComplex)
            {
                return(ComplexOps.FloorDivide(Complex64.MakeReal(x), ((ExtensibleComplex)other).value));
            }
            else if (other is byte)
            {
                int y = (int)((byte)other);
                try {
                    return(Ops.Long2Object(Divide(x, y)));
                } catch (OverflowException) {
                    return(BigInteger.Create(x) / y);
                }
            }

            return(Ops.NotImplemented);
        }
 public static object FloorDivide(int x, object other)
 {
     if (other is int)
     {
         int y = (int)other;
         try {
             return(Ops.Int2Object(Divide(x, y)));
         } catch (OverflowException) {
             return(LongOps.FloorDivide(BigInteger.Create(x), y));
         }
     }
     else if (other is BigInteger)
     {
         return(LongOps.FloorDivide(BigInteger.Create(x), (BigInteger)other));
     }
     else if (other is double)
     {
         return(FloatOps.FloorDivide(x, (double)other));
     }
     else if (other is Complex64)
     {
         Complex64 y = (Complex64)other;
         if (y.IsZero)
         {
             throw Ops.ZeroDivisionError();
         }
         return(ComplexOps.FloorDivide(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(Divide(x, y));
         } catch (OverflowException) {
             return(LongOps.FloorDivide(BigInteger.Create(x), y));
         }
     }
     else if (other is float)
     {
         return(FloatOps.FloorDivide(x, (float)other));
     }
     else if (other is byte)
     {
         return(Ops.Int2Object(Divide(x, (int)((byte)other))));
     }
     else if (other is ExtensibleInt)
     {
         int y = ((ExtensibleInt)other).value;
         try {
             return(Ops.Int2Object(Divide(x, y)));
         } catch (OverflowException) {
             return(LongOps.FloorDivide(BigInteger.Create(x), y));
         }
     }
     else if (other is ExtensibleFloat)
     {
         return(FloatOps.FloorDivide(x, ((ExtensibleFloat)other).value));
     }
     else if (other is ExtensibleComplex)
     {
         Complex64 y = ((ExtensibleComplex)other).value;
         if (y.IsZero)
         {
             throw Ops.ZeroDivisionError();
         }
         return(ComplexOps.FloorDivide(Complex64.MakeReal(x), y));
     }
     return(Ops.NotImplemented);
 }