diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 15:51:55 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 15:51:55 (GMT) |
commit | efc82f7e8eff19d8e844a3dc268a88de7fbcb173 (patch) | |
tree | 58198f2e7610ba6d33865884487de006de30af85 /Lib | |
parent | c8e81ef508f0f1dc4e5c31bd0bec2766867fead5 (diff) | |
download | cpython-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')
-rw-r--r-- | Lib/test/test_long.py | 31 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 15 |
2 files changed, 40 insertions, 6 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]) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 128880d..a4554a6 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -332,6 +332,9 @@ class SysModuleTest(unittest.TestCase): self.assert_(isinstance(sys.executable, basestring)) self.assertEqual(len(sys.float_info), 11) self.assertEqual(sys.float_info.radix, 2) + self.assertEqual(len(sys.long_info), 2) + self.assert_(sys.long_info.bits_per_digit % 5 == 0) + self.assert_(sys.long_info.sizeof_digit >= 1) self.assert_(isinstance(sys.hexversion, int)) self.assert_(isinstance(sys.maxint, int)) if test.test_support.have_unicode: @@ -417,6 +420,7 @@ class SizeofTest(unittest.TestCase): if hasattr(sys, "gettotalrefcount"): self.header += '2P' self.vheader += '2P' + self.longdigit = sys.long_info.sizeof_digit import _testcapi self.gc_headsize = _testcapi.SIZEOF_PYGC_HEAD self.file = open(test.test_support.TESTFN, 'wb') @@ -594,11 +598,12 @@ class SizeofTest(unittest.TestCase): check(reversed([]), size(h + 'lP')) # long check(0L, size(vh)) - check(1L, size(vh) + self.H) - check(-1L, size(vh) + self.H) - check(32768L, size(vh) + 2*self.H) - check(32768L*32768L-1, size(vh) + 2*self.H) - check(32768L*32768L, size(vh) + 3*self.H) + check(1L, size(vh) + self.longdigit) + check(-1L, size(vh) + self.longdigit) + PyLong_BASE = 2**sys.long_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) # module check(unittest, size(h + 'P')) # None |