Ejemplo n.º 1
0
 def test_fromfloat(self):
     x = 1234567890.1234567890
     f1 = rbigint.fromfloat(x)
     y = f1.tofloat()
     assert f1.tolong() == long(x)
     # check overflow
     #x = 12345.6789e10000000000000000000000000000
     # XXX don't use such consts. marshal doesn't handle them right.
     x = 12345.6789e200
     x *= x
     assert raises(OverflowError, rbigint.fromfloat, x)
     #
     f1 = rbigint.fromfloat(9007199254740991.0)
     assert f1.tolong() == 9007199254740991
Ejemplo n.º 2
0
 def test_tofloat_precision(self):
     assert rbigint.fromlong(0).tofloat() == 0.0
     for sign in [1, -1]:
         for p in xrange(100):
             x = long(2**p * (2**53 + 1) + 1) * sign
             y = long(2**p * (2**53+ 2)) * sign
             rx = rbigint.fromlong(x)
             rxf = rx.tofloat()
             assert rxf == float(y)
             assert rbigint.fromfloat(rxf).tolong() == y
             #
             x = long(2**p * (2**53 + 1)) * sign
             y = long(2**p * 2**53) * sign
             rx = rbigint.fromlong(x)
             rxf = rx.tofloat()
             assert rxf == float(y)
             assert rbigint.fromfloat(rxf).tolong() == y
Ejemplo n.º 3
0
 def do_compare_bigint(f1, b2):
     """f1 is a float.  b2 is a bigint."""
     if not isfinite(f1) or math.floor(f1) != f1:
         return opname == 'ne'
     b1 = rbigint.fromfloat(f1)
     res = b1.eq(b2)
     if opname == 'ne':
         res = not res
     return res
Ejemplo n.º 4
0
 def do_compare_bigint(f1, b2):
     """f1 is a float.  b2 is a bigint."""
     if not isfinite(f1) or math.floor(f1) != f1:
         return opname == 'ne'
     b1 = rbigint.fromfloat(f1)
     res = b1.eq(b2)
     if opname == 'ne':
         res = not res
     return res
Ejemplo n.º 5
0
 def do_compare_bigint(f1, b2):
     """f1 is a float.  b2 is a bigint."""
     if not isfinite(f1):
         return op(f1, 0.0)
     if opname == 'gt' or opname == 'le':
         # 'float > long'   <==>  'ceil(float) > long'
         # 'float <= long'  <==>  'ceil(float) <= long'
         f1 = math.ceil(f1)
     else:
         # 'float < long'   <==>  'floor(float) < long'
         # 'float >= long'  <==>  'floor(float) >= long'
         f1 = math.floor(f1)
     b1 = rbigint.fromfloat(f1)
     return getattr(b1, opname)(b2)
Ejemplo n.º 6
0
 def do_compare_bigint(f1, b2):
     """f1 is a float.  b2 is a bigint."""
     if not isfinite(f1):
         return op(f1, 0.0)
     if opname == 'gt' or opname == 'le':
         # 'float > long'   <==>  'ceil(float) > long'
         # 'float <= long'  <==>  'ceil(float) <= long'
         f1 = math.ceil(f1)
     else:
         # 'float < long'   <==>  'floor(float) < long'
         # 'float >= long'  <==>  'floor(float) >= long'
         f1 = math.floor(f1)
     b1 = rbigint.fromfloat(f1)
     return getattr(b1, opname)(b2)
Ejemplo n.º 7
0
 def fromfloat(f):
     return W_LongObject(rbigint.fromfloat(f))
Ejemplo n.º 8
0
 def fromfloat(space, f):
     return newlong(space, rbigint.fromfloat(f))
Ejemplo n.º 9
0
 def fromfloat(space, f):
     return newlong(space, rbigint.fromfloat(f))
Ejemplo n.º 10
0
 def fromfloat(f):
     return W_LongObject(rbigint.fromfloat(f))