Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: math-improvements
Changeset: r93757:744cb1dc4f2e
Date: 2018-02-05 11:49 +0100
http://bitbucket.org/pypy/pypy/changeset/744cb1dc4f2e/
Log: fix rbigint.int_divmod
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -949,24 +949,23 @@
if not int_in_valid_range(w) or (wsign == -1 and v.sign != wsign):
# Just fallback.
return v.divmod(rbigint.fromint(w))
-
+
digit = abs(w)
assert digit > 0
div, mod = _divrem1(v, digit)
div.sign = v.sign * wsign
-
- if v.sign != wsign:
+ if v.sign < 0:
+ mod = -mod
+ if mod and v.sign * wsign == -1:
+ mod += w
if div.sign == 0:
div = ONENEGATIVERBIGINT
else:
div = div.int_sub(1)
- mod = w - mod
-
- mod = rbigint.fromint(wsign * mod)
-
+ mod = rbigint.fromint(mod)
return div, mod
-
+
@jit.elidable
def pow(a, b, c=None):
negativeOutput = False # if x<0 return negative output
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
@@ -902,8 +902,6 @@
for sx, sy in (1, 1), (1, -1), (-1, -1), (-1, 1):
sx *= x
sy *= y
- if sx == 0 and sy == 1:
- import pdb; pdb.set_trace()
if sy == sys.maxint + 1:
continue
f1 = rbigint.fromlong(sx)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit