Author: stian
Branch: math-improvements
Changeset: r93092:e6c9af023bc5
Date: 2017-11-20 14:19 +0100
http://bitbucket.org/pypy/pypy/changeset/e6c9af023bc5/
Log: Test and fix for int rbinop overflow to long, also add a deeper test
for int_floordiv
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -589,7 +589,7 @@
try:
return func(space, y, x)
except OverflowError:
- return ovf2long(space, y, x, w_other)
+ return ovf2long(space, y, x, self)
else:
return func(space, y, x)
diff --git a/pypy/objspace/std/test/test_intobject.py
b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -613,6 +613,9 @@
assert type(x) is int
assert str(x) == "0"
+ def test_rbinop_overflow(self):
+ x = int(321)
+ assert x.__rlshift__(333) ==
1422567365923326114875084456308921708325401211889530744784729710809598337369906606315292749899759616L
class AppTestIntShortcut(AppTestInt):
spaceconfig = {"objspace.std.intshortcut": True}
diff --git a/rpython/rlib/test/test_rbigint.py
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -70,6 +70,15 @@
r2 = r.int_floordiv(10)
assert r2.tolong() == 100L
+ for op1 in gen_signs(long_vals):
+ for op2 in gen_signs(long_vals):
+ if not op2 or op2 >= (1 << SHIFT) or op2 <= -(1 << SHIFT):
+ continue
+ rl_op1 = rbigint.fromlong(op1)
+ r1 = rl_op1.int_floordiv(op2)
+ r2 = op1 // op2
+ assert r1.tolong() == r2
+
assert py.test.raises(ZeroDivisionError, r.int_floordiv, 0)
# Error pointed out by Armin Rigo
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit