summaryrefslogtreecommitdiffstats
path: root/Lib
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
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')
-rw-r--r--Lib/test/test_long.py31
-rw-r--r--Lib/test/test_sys.py23
2 files changed, 44 insertions, 10 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))
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 9f0c139..427b721 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -333,6 +333,9 @@ class SysModuleTest(unittest.TestCase):
self.assert_(isinstance(sys.executable, str))
self.assertEqual(len(sys.float_info), 11)
self.assertEqual(sys.float_info.radix, 2)
+ self.assertEqual(len(sys.int_info), 2)
+ self.assert_(sys.int_info.bits_per_digit % 5 == 0)
+ self.assert_(sys.int_info.sizeof_digit >= 1)
self.assert_(isinstance(sys.hexversion, int))
self.assert_(isinstance(sys.maxsize, int))
self.assert_(isinstance(sys.maxunicode, int))
@@ -437,6 +440,7 @@ class SizeofTest(unittest.TestCase):
if hasattr(sys, "gettotalrefcount"):
self.header += '2P'
self.vheader += '2P'
+ self.longdigit = sys.int_info.sizeof_digit
import _testcapi
self.gc_headsize = _testcapi.SIZEOF_PYGC_HEAD
self.file = open(test.support.TESTFN, 'wb')
@@ -471,7 +475,7 @@ class SizeofTest(unittest.TestCase):
size = self.calcsize
gc_header_size = self.gc_headsize
# bool objects are not gc tracked
- self.assertEqual(sys.getsizeof(True), size(vh) + self.H)
+ self.assertEqual(sys.getsizeof(True), size(vh) + self.longdigit)
# but lists are
self.assertEqual(sys.getsizeof([]), size(vh + 'PP') + gc_header_size)
@@ -479,8 +483,8 @@ class SizeofTest(unittest.TestCase):
h = self.header
vh = self.vheader
size = self.calcsize
- self.assertEqual(sys.getsizeof(True), size(vh) + self.H)
- self.assertEqual(sys.getsizeof(True, -1), size(vh) + self.H)
+ self.assertEqual(sys.getsizeof(True), size(vh) + self.longdigit)
+ self.assertEqual(sys.getsizeof(True, -1), size(vh) + self.longdigit)
def test_objecttypes(self):
# check all types defined in Objects/
@@ -489,7 +493,7 @@ class SizeofTest(unittest.TestCase):
size = self.calcsize
check = self.check_sizeof
# bool
- check(True, size(vh) + self.H)
+ check(True, size(vh) + self.longdigit)
# buffer
# XXX
# builtin_function_or_method
@@ -607,11 +611,12 @@ class SizeofTest(unittest.TestCase):
check(reversed([]), size(h + 'lP'))
# long
check(0, size(vh))
- check(1, size(vh) + self.H)
- check(-1, size(vh) + self.H)
- check(32768, size(vh) + 2*self.H)
- check(32768*32768-1, size(vh) + 2*self.H)
- check(32768*32768, size(vh) + 3*self.H)
+ check(1, size(vh) + self.longdigit)
+ check(-1, size(vh) + self.longdigit)
+ PyLong_BASE = 2**sys.int_info.bits_per_digit
+ check(PyLong_BASE, size(vh) + 2*self.longdigit)
+ check(PyLong_BASE**2-1, size(vh) + 2*self.longdigit)
+ check(PyLong_BASE**2, size(vh) + 3*self.longdigit)
# memory
check(memoryview(b''), size(h + 'P PP2P2i7P'))
# module