Ejemplo n.º 1
0
 private static object TrueDivide(long x, BigInteger y)
 {
     if (y == BigInteger.Zero) {
         throw new DivideByZeroException();
     }
     return (double)x / y.ToFloat64();
 }
Ejemplo n.º 2
0
 private static object TrueDivide(BigInteger x, double y)
 {
     if (y == 0.0) {
         throw new DivideByZeroException();
     }
     return x.ToFloat64() / y;
 }
Ejemplo n.º 3
0
 private static object TrueDivide(BigInteger x, BigInteger y)
 {
     if (y == BigInteger.Zero) {
         throw new DivideByZeroException();
     }
     return x.ToFloat64() / y.ToFloat64();
 }
Ejemplo n.º 4
0
 public static object ToFloat(BigInteger self)
 {
     return self.ToFloat64();
 }
Ejemplo n.º 5
0
 //[PythonName("__pow__")]
 public static object Power(BigInteger x, double y)
 {
     return FloatOps.Power(x.ToFloat64(), y);
 }
Ejemplo n.º 6
0
 //[PythonName("__pow__")]
 public static object Power(BigInteger x, long y)
 {
     if ((int)y == y) {
         return Power(x, (int)y);
     } else {
         if (y < 0) {
             return FloatOps.Power(x.ToFloat64(), y);
         }
         if (x == BigInteger.Zero) {
             return BigInteger.Zero;
         } else if (x == BigInteger.One) {
             return BigInteger.One;
         } else {
             throw Ops.ValueError("Number too big");
         }
     }
 }
Ejemplo n.º 7
0
 //[PythonName("__pow__")]
 public static object Power(BigInteger x, int y)
 {
     if (y < 0) {
         return FloatOps.Power(x.ToFloat64(), y);
     }
     return x.Power(y);
 }
Ejemplo n.º 8
0
        public static object Compare(BigInteger x, object y)
        {
            if (y == null) return 1;

            int intVal;
            if (y is int) {
                if (x.AsInt32(out intVal)) return IntOps.Compare(intVal, y);
            } else if (y is ExtensibleInt) {
                if (x.AsInt32(out intVal)) return IntOps.Compare(intVal, ((ExtensibleInt)y).value);
            } else if (y is double) {
                return ((int)FloatOps.Compare((double)y, x)) * -1;
            } else if (y is ExtensibleFloat) {
                double dbl = x.ToFloat64();
                return FloatOps.Compare(dbl, ((ExtensibleFloat)y).value);
            } else if (y is bool) {
                if (x.AsInt32(out intVal)) return IntOps.Compare(intVal, ((bool)y) ? 1 : 0);
            } else if (y is decimal) {
                double dbl = x.ToFloat64();
                return FloatOps.Compare(dbl, y);
            }

            BigInteger bi;
            if (!Converter.TryConvertToBigInteger(y, out bi)) {
                object res = Ops.GetDynamicType(y).Coerce(y, x);
                if (res != Ops.NotImplemented && !(res is OldInstance)) {
                    return Ops.Compare(((Tuple)res)[1], ((Tuple)res)[0]);
                }
                return Ops.NotImplemented;
            }

            BigInteger diff = x - bi;
            if (diff == 0) return 0;
            else if (diff < 0) return -1;
            else return 1;
        }