Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r96988:c79c569bdd04 Date: 2019-07-14 10:50 +0200 http://bitbucket.org/pypy/pypy/changeset/c79c569bdd04/
Log: Fix the test and the implementation of gcd_binary() diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -2971,15 +2971,15 @@ def gcd_binary(a, b): """ Compute the greatest common divisor of non-negative integers a and b using the binary GCD algorithm. Raises ValueError on negative input. """ + if a < 0 or b < 0: + raise ValueError + if a == 0: return b if b == 0: return a - if a < 0 or b < 0: - raise ValueError - shift = 0 while (a | b) & 1 == 0: a >>= 1 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 @@ -839,7 +839,7 @@ def test_gcd(self): assert gcd_binary(2*3*7**2, 2**2*7) == 2*7 - assert gcd_binary(2*3*7**2, -2**2*7) == 2*7 + pytest.raises(ValueError, gcd_binary, 2*3*7**2, -2**2*7) assert gcd_binary(1234, 5678) == 2 assert gcd_binary(13, 13**6) == 13 assert gcd_binary(12, 0) == 12 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit