summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-03-20 15:51:55 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-03-20 15:51:55 (GMT)
commitefc82f7e8eff19d8e844a3dc268a88de7fbcb173 (patch)
tree58198f2e7610ba6d33865884487de006de30af85 /Lib/test/test_long.py
parentc8e81ef508f0f1dc4e5c31bd0bec2766867fead5 (diff)
downloadcpython-efc82f7e8eff19d8e844a3dc268a88de7fbcb173.zip
cpython-efc82f7e8eff19d8e844a3dc268a88de7fbcb173.tar.gz
cpython-efc82f7e8eff19d8e844a3dc268a88de7fbcb173.tar.bz2
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Backport of r70459.
Diffstat (limited to 'Lib/test/test_long.py')
-rw-r--r--Lib/test/test_long.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index e648c0f..1a0e33d 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -15,7 +15,7 @@ class Frm(object):
return self.format % self.args
# SHIFT should match the value in longintrepr.h for best testing.
-SHIFT = 15
+SHIFT = sys.long_info.bits_per_digit
BASE = 2 ** SHIFT
MASK = BASE - 1
KARATSUBA_CUTOFF = 70 # from longobject.c
@@ -143,6 +143,35 @@ class LongTest(unittest.TestCase):
y = self.getran(leny) or 1L
self.check_division(x, y)
+ # specific numbers chosen to exercise corner cases of the
+ # current long division implementation
+
+ # 30-bit cases involving a quotient digit estimate of BASE+1
+ self.check_division(1231948412290879395966702881L,
+ 1147341367131428698L)
+ self.check_division(815427756481275430342312021515587883L,
+ 707270836069027745L)
+ self.check_division(627976073697012820849443363563599041L,
+ 643588798496057020L)
+ self.check_division(1115141373653752303710932756325578065L,
+ 1038556335171453937726882627L)
+ # 30-bit cases that require the post-subtraction correction step
+ self.check_division(922498905405436751940989320930368494L,
+ 949985870686786135626943396L)
+ self.check_division(768235853328091167204009652174031844L,
+ 1091555541180371554426545266L)
+
+ # 15-bit cases involving a quotient digit estimate of BASE+1
+ self.check_division(20172188947443L, 615611397L)
+ self.check_division(1020908530270155025L, 950795710L)
+ self.check_division(128589565723112408L, 736393718L)
+ self.check_division(609919780285761575L, 18613274546784L)
+ # 15-bit cases that require the post-subtraction correction step
+ self.check_division(710031681576388032L, 26769404391308L)
+ self.check_division(1933622614268221L, 30212853348836L)
+
+
+
def test_karatsuba(self):
digits = range(1, 5) + range(KARATSUBA_CUTOFF, KARATSUBA_CUTOFF + 10)
digits.extend([KARATSUBA_CUTOFF * 10, KARATSUBA_CUTOFF * 100])