Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de>
Branch: math-improvements
Changeset: r93758:f6e9839f73ac
Date: 2018-02-05 12:01 +0100
http://bitbucket.org/pypy/pypy/changeset/f6e9839f73ac/

Log:    remove copy-pasted code between mod and int_mod

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -837,32 +837,9 @@
             return NULLRBIGINT
 
         if other.sign != 0 and other.numdigits() == 1:
-            digit = other.digit(0)
-            if digit == 1:
-                return NULLRBIGINT
-            elif digit == 2:
-                modm = self.digit(0) & 1
-                if modm:
-                    return ONENEGATIVERBIGINT if other.sign == -1 else 
ONERBIGINT
-                return NULLRBIGINT
-            elif digit & (digit - 1) == 0:
-                mod = self.int_and_(digit - 1)
-            else:
-                # Perform
-                size = UDIGIT_TYPE(self.numdigits() - 1)
-                
-                if size > 0:
-                    wrem = self.widedigit(size)
-                    while size > 0:
-                        size -= 1
-                        wrem = ((wrem << SHIFT) | self.digit(size)) % digit
-                    rem = _store_digit(wrem)
-                else:
-                    rem = _store_digit(self.digit(0) % digit)
-
-                if rem == 0:
-                    return NULLRBIGINT
-                mod = rbigint([rem], -1 if self.sign < 0 else 1, 1)
+            otherint = other.digit(0) * other.sign
+            assert int_in_valid_range(otherint)
+            return self.int_mod(otherint)
         else:
             div, mod = _divrem(self, other)
         if mod.sign * other.sign == -1:
@@ -892,7 +869,7 @@
             else:
                 # Perform
                 size = UDIGIT_TYPE(self.numdigits() - 1)
-                
+
                 if size > 0:
                     wrem = self.widedigit(size)
                     while size > 0:
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to