summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-03-18 20:06:12 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-03-18 20:06:12 (GMT)
commitbd7926478de92a2a0ef4440e1a9ae61b706a80d2 (patch)
treef92ef0133e96195e1875cc74b046474aeb7be155 /Lib/test/test_long.py
parente7f45b8e5948d7367c3754b0506b082d1296138f (diff)
downloadcpython-bd7926478de92a2a0ef4440e1a9ae61b706a80d2.zip
cpython-bd7926478de92a2a0ef4440e1a9ae61b706a80d2.tar.gz
cpython-bd7926478de92a2a0ef4440e1a9ae61b706a80d2.tar.bz2
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
- new configure option --enable-big-digits - new structseq sys.int_info giving information about the internal format By default, 30-bit digits are enabled on 64-bit machines but disabled on 32-bit machines.
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 0e07090..92285b2 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.int_info.bits_per_digit
BASE = 2 ** SHIFT
MASK = BASE - 1
KARATSUBA_CUTOFF = 70 # from longobject.c
@@ -120,6 +120,35 @@ class LongTest(unittest.TestCase):
y = self.getran(leny) or 1
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(1231948412290879395966702881,
+ 1147341367131428698)
+ self.check_division(815427756481275430342312021515587883,
+ 707270836069027745)
+ self.check_division(627976073697012820849443363563599041,
+ 643588798496057020)
+ self.check_division(1115141373653752303710932756325578065,
+ 1038556335171453937726882627)
+ # 30-bit cases that require the post-subtraction correction step
+ self.check_division(922498905405436751940989320930368494,
+ 949985870686786135626943396)
+ self.check_division(768235853328091167204009652174031844,
+ 1091555541180371554426545266)
+
+ # 15-bit cases involving a quotient digit estimate of BASE+1
+ self.check_division(20172188947443, 615611397)
+ self.check_division(1020908530270155025, 950795710)
+ self.check_division(128589565723112408, 736393718)
+ self.check_division(609919780285761575, 18613274546784)
+ # 15-bit cases that require the post-subtraction correction step
+ self.check_division(710031681576388032, 26769404391308)
+ self.check_division(1933622614268221, 30212853348836)
+
+
+
def test_karatsuba(self):
digits = list(range(1, 5)) + list(range(KARATSUBA_CUTOFF,
KARATSUBA_CUTOFF + 10))