[pypy-commit] pypy math-improvements: Remove unused variable and make these size calculations unsigned

stian pypy.commits at gmail.com
Thu Nov 9 07:38:27 EST 2017


Author: stian
Branch: math-improvements
Changeset: r92982:1a7dc37b2d5d
Date: 2017-11-09 13:37 +0100
http://bitbucket.org/pypy/pypy/changeset/1a7dc37b2d5d/

Log:	Remove unused variable and make these size calculations unsigned

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -848,14 +848,14 @@
                 mod = self.int_and_(digit - 1)
             else:
                 # Perform
-                size = self.numdigits() - 1
+                size = UDIGIT_TYPE(self.numdigits() - 1)
                 
                 if size > 0:
                     rem = self.widedigit(size)
-                    size -= 1
-                    while size >= 0:
+                    while size > 0:
+                        size -= 1
                         rem = ((rem << SHIFT) | self.digit(size)) % digit
-                        size -= 1
+                        
                 else:
                     rem = self.widedigit(0) % digit
 
@@ -890,13 +890,13 @@
                 mod = self.int_and_(digit - 1)
             else:
                 # Perform
-                size = self.numdigits() - 1
+                size = UDIGIT_TYPE(self.numdigits() - 1)
+                
                 if size > 0:
                     rem = self.widedigit(size)
-                    size -= 1
-                    while size >= 0:
+                    while size > 0:
+                        size -= 1
                         rem = ((rem << SHIFT) | self.digit(size)) % digit
-                        size -= 1
                 else:
                     rem = self.digit(0) % digit
 
@@ -981,7 +981,7 @@
             # XXX failed to implement
             raise ValueError("bigint pow() too negative")
 
-        size_b = b.numdigits()
+        size_b = UDIGIT_TYPE(b.numdigits())
 
         if b.sign == 0:
             return ONERBIGINT
@@ -1040,8 +1040,9 @@
         if size_b <= FIVEARY_CUTOFF:
             # Left-to-right binary exponentiation (HAC Algorithm 14.79)
             # http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf
-            size_b -= 1
-            while size_b >= 0:
+
+            while size_b > 0:
+                size_b -= 1
                 bi = b.digit(size_b)
                 j = 1 << (SHIFT-1)
                 while j != 0:
@@ -1049,7 +1050,7 @@
                     if bi & j:
                         z = _help_mult(z, a, c)
                     j >>= 1
-                size_b -= 1
+                
 
         else:
             # Left-to-right 5-ary exponentiation (HAC Algorithm 14.82)
@@ -1328,7 +1329,7 @@
         hishift = SHIFT - loshift
         z = rbigint([NULLDIGIT] * newsize, self.sign, newsize)
         i = 0
-        inverted = False
+
         while i < newsize:
             digit = self.udigit(wordshift)
             if invert and i == 0 and wordshift == 0:


More information about the pypy-commit mailing list