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);
 }
示例#2
0
        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 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);
 }