Author: Stian Andreassen
Branch: math-improvements
Changeset: r95475:918c7b88d892
Date: 2018-12-13 18:10 +0100
http://bitbucket.org/pypy/pypy/changeset/918c7b88d892/

Log:    Fix _x_divrem (thanks Carl Friedrich Bolz-Tereick for the test)

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -2073,12 +2073,15 @@
         if j >= size_v:
             vtop = 0
         else:
-            vtop = v.widedigit(j) << SHIFT
-
-        vv = vtop | v.digit(abs(j-1))
+            vtop = v.widedigit(j)
+        assert vtop <= wm1
+        
+        vv = (vtop << SHIFT) | v.widedigit(abs(j-1))
+        
         # Hints to make division just as fast as doing it unsigned. But avoids 
casting to get correct results.
         assert vv >= 0
         assert wm1 >= 1
+        
         q = vv / wm1
         r = vv % wm1 # This seems to be slightly faster on widen digits than 
vv - wm1 * q.
         vj2 = v.digit(abs(j-2))
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to