Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: py3.7 Changeset: r98529:0d41cb5cfe59 Date: 2020-01-14 13:21 +0100 http://bitbucket.org/pypy/pypy/changeset/0d41cb5cfe59/
Log: make num >> (huge int) return 0 or -1 diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py --- a/pypy/objspace/std/longobject.py +++ b/pypy/objspace/std/longobject.py @@ -325,7 +325,10 @@ raise oefmt(space.w_ValueError, "negative shift count") try: shift = w_other.asbigint().toint() - except OverflowError: # b too big # XXX maybe just return 0L instead? + except OverflowError: + if self.num.sign < 0: + return space.newint(-1) + return space.newint(0) raise oefmt(space.w_OverflowError, "shift count too large") return newlong(space, self.num.rshift(shift)) diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py --- a/pypy/objspace/std/test/test_longobject.py +++ b/pypy/objspace/std/test/test_longobject.py @@ -212,9 +212,13 @@ raises(OverflowError, "long(1) << (2 ** 100)") raises(ValueError, "long(1) >> long(-1)") raises(ValueError, "long(1) >> -1") - raises(OverflowError, "long(1) >> (2 ** 100)") + assert long(1) >> (2 ** 100) == 0 + assert long(-1) >> (2 ** 100) == -1 + assert 1 >> (2 ** 100) == 0 # int compatibility + assert -1 >> (2 ** 100) == -1 # int compatibility assert 0 << (1 << 1000) == 0 + def test_pow(self): long = self._long x = self._long(0) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit