[pypy-svn] pypy default: Fix a long.__truediv__ corner case by using a version of divmod() that does not depend

amauryfa commits-noreply at bitbucket.org
Thu Feb 10 14:43:15 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r41773:e2b10fbcbaeb
Date: 2011-02-10 13:45 +0100
http://bitbucket.org/pypy/pypy/changeset/e2b10fbcbaeb/

Log:	Fix a long.__truediv__ corner case by using a version of divmod()
	that does not depend on the sign of the arguments.

diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -57,9 +57,25 @@
         op2 = rbigint.fromlong(1)
         f = op1.truediv(op2)
         assert f == 1.7976931348623157e+308     # exactly
+
+        op2 = rbigint.fromlong(-1)
+        f = op1.truediv(op2)
+        assert f == -1.7976931348623157e+308    # exactly
+
         op1 = rbigint.fromlong(overflowing)
+        op2 = rbigint.fromlong(1)
         py.test.raises(OverflowError, op1.truediv, op2)
 
+    def test_truediv_overflow2(self):
+        overflowing = 2**1024 - 2**(1024-53-1)
+        op1 = rbigint.fromlong(2*overflowing - 10)
+        op2 = rbigint.fromlong(2)
+        f = op1.truediv(op2)
+        assert f == 1.7976931348623157e+308    # exactly
+        op2 = rbigint.fromlong(-2)
+        f = op1.truediv(op2)
+        assert f == -1.7976931348623157e+308   # exactly
+
     def test_mod(self):
         for op1 in [-50, -12, -2, -1, 1, 2, 50, 52]:
             for op2 in [-4, -2, -1, 1, 2, 8]:

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -1503,7 +1503,7 @@
             inexact = True
 
     # x //= b. If the remainder is nonzero, set inexact.
-    x, rem = x.divmod(b)
+    x, rem = _divrem(x, b)
     if rem.tobool():
         inexact = True
 


More information about the Pypy-commit mailing list