Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de>
Branch: py3.6
Changeset: r96964:fb80c6375d86
Date: 2019-07-11 11:21 +0200
http://bitbucket.org/pypy/pypy/changeset/fb80c6375d86/

Log:    merge default

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -2969,13 +2969,16 @@
 
 
 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:
         return b
 
     if b == 0:
         return a
 
-    a, b = abs(a), abs(b)
+    if a < 0 or b < 0:
+        raise ValueError
 
     shift = 0
     while (a | b) & 1 == 0:
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,13 +839,13 @@
 
     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
         assert gcd_binary(2*3*7**2, -2**2*7) == 2*7
-        assert gcd_binary(-2*3*7**2, -2**2*7) == 2*7
         assert gcd_binary(1234, 5678) == 2
         assert gcd_binary(13, 13**6) == 13
         assert gcd_binary(12, 0) == 12
         assert gcd_binary(0, 0) == 0
+        assert pytest.raises(ValueError, gcd_binary, -10, 0)
+        assert pytest.raises(ValueError, gcd_binary, 10, -10)
 
         x = rbigint.fromlong(9969216677189303386214405760200)
         y = rbigint.fromlong(16130531424904581415797907386349)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to