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