Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: math-improvements
Changeset: r93764:3ee3f44df079
Date: 2018-02-05 13:08 +0100
http://bitbucket.org/pypy/pypy/changeset/3ee3f44df079/

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
@@ -831,10 +831,12 @@
 
     @jit.elidable
     def mod(self, other):
+        if other.sign == 0:
+            raise ZeroDivisionError("long division or modulo by zero")
         if self.sign == 0:
             return NULLRBIGINT
 
-        if other.sign != 0 and other.numdigits() == 1:
+        if other.numdigits() == 1:
             otherint = other.digit(0) * other.sign
             assert int_in_valid_range(otherint)
             return self.int_mod(otherint)
@@ -846,6 +848,8 @@
 
     @jit.elidable
     def int_mod(self, other):
+        if other == 0:
+            raise ZeroDivisionError("long division or modulo by zero")
         if self.sign == 0:
             return NULLRBIGINT
 
@@ -853,7 +857,7 @@
             # Fallback to long.
             return self.mod(rbigint.fromint(other))
 
-        elif other != 0:
+        if 1: # preserve indentation to preserve history
             digit = abs(other)
             if digit == 1:
                 return NULLRBIGINT
@@ -880,8 +884,6 @@
                 if rem == 0:
                     return NULLRBIGINT
                 mod = rbigint([rem], -1 if self.sign < 0 else 1, 1)
-        else:
-            raise ZeroDivisionError("long division or modulo by zero")
 
         if mod.sign * (-1 if other < 0 else 1) == -1:
             mod = mod.int_add(other)
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
@@ -165,11 +165,12 @@
 
     def test_mod(self):
         for op1 in gen_signs(long_vals):
+            rl_op1 = rbigint.fromlong(op1)
             for op2 in gen_signs(long_vals):
+                rl_op2 = rbigint.fromlong(op2)
                 if not op2:
+                    py.test.raises(ZeroDivisionError, rl_op1.mod, rl_op2)
                     continue
-                rl_op1 = rbigint.fromlong(op1)
-                rl_op2 = rbigint.fromlong(op2)
                 r1 = rl_op1.mod(rl_op2)
                 r2 = op1 % op2
 
@@ -177,10 +178,11 @@
 
     def test_int_mod(self):
         for x in gen_signs(long_vals):
+            op1 = rbigint.fromlong(x)
             for y in signed_int_vals:
                 if not y:
+                    py.test.raises(ZeroDivisionError, op1.int_mod, 0)
                     continue
-                op1 = rbigint.fromlong(x)
                 r1 = op1.int_mod(y)
                 r2 = x % y
                 assert r1.tolong() == r2
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to