[pypy-commit] pypy math-improvements: remove code duplication in floordiv
cfbolz
pypy.commits at gmail.com
Mon Feb 5 06:38:20 EST 2018
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: math-improvements
Changeset: r93759:5c8a03028ed8
Date: 2018-02-05 12:27 +0100
http://bitbucket.org/pypy/pypy/changeset/5c8a03028ed8/
Log: remove code duplication in floordiv
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -783,12 +783,10 @@
@jit.elidable
def floordiv(self, other):
- if self.sign == 1 and other.numdigits() == 1 and other.sign == 1:
- digit = other.digit(0)
- if digit == 1:
- return self
- elif digit & (digit - 1) == 0:
- return self.rqshift(ptwotable[digit])
+ if other.numdigits() == 1:
+ otherint = other.digit(0) * other.sign
+ assert int_in_valid_range(otherint)
+ return self.int_floordiv(otherint)
div, mod = _divrem(self, other)
if mod.sign * other.sign == -1:
@@ -800,13 +798,13 @@
def div(self, other):
return self.floordiv(other)
-
+
@jit.elidable
def int_floordiv(self, b):
if not int_in_valid_range(b):
# Fallback to long.
return self.floordiv(rbigint.fromint(b))
-
+
if b == 0:
raise ZeroDivisionError("long division by zero")
@@ -818,7 +816,7 @@
return self
elif digit & (digit - 1) == 0:
return self.rqshift(ptwotable[digit])
-
+
div, mod = _divrem1(self, digit)
if mod != 0 and self.sign * (-1 if b < 0 else 1) == -1:
@@ -830,7 +828,7 @@
def int_div(self, other):
return self.int_floordiv(other)
-
+
@jit.elidable
def mod(self, other):
if self.sign == 0:
More information about the pypy-commit
mailing list