summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-12-04 23:05:10 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-12-04 23:05:10 (GMT)
commita3c01ce696cdbc0d8236a002cc76103db5662a1b (patch)
tree63424e93418396b4304ad7ee48ef78f1eeea25ee /Lib
parentd2a557e51eeb3d6fc444caab496d855dcbc2953b (diff)
downloadcpython-a3c01ce696cdbc0d8236a002cc76103db5662a1b.zip
cpython-a3c01ce696cdbc0d8236a002cc76103db5662a1b.tar.gz
cpython-a3c01ce696cdbc0d8236a002cc76103db5662a1b.tar.bz2
SF bug #488480: integer multiply to return -max_int-1.
int_mul(): new and vastly simpler overflow checking. Whether it's faster or slower will likely vary across platforms, favoring boxes with fast floating point. OTOH, we no longer have to worry about people shipping broken LONG_BIT definitions <0.9 wink>.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_types.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index c0c1c88..3af3113 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -71,6 +71,32 @@ if not -24 < -12: raise TestFailed, 'int op'
xsize, ysize, zsize = 238, 356, 4
if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
raise TestFailed, 'int mul commutativity'
+# And another.
+m = -sys.maxint - 1
+for divisor in 1, 2, 4, 8, 16, 32:
+ j = m / divisor
+ prod = divisor * j
+ if prod != m:
+ raise TestFailed, "%r * %r == %r != %r" % (divisor, j, prod, m)
+ if type(prod) is not int:
+ raise TestFailed, ("expected type(prod) to be int, not %r" %
+ type(prod))
+# Check for expected * overflow to long.
+for divisor in 1, 2, 4, 8, 16, 32:
+ j = m / divisor - 1
+ prod = divisor * j
+ if type(prod) is not long:
+ raise TestFailed, ("expected type(%r) to be long, not %r" %
+ (prod, type(prod)))
+# Check for expected * overflow to long.
+m = sys.maxint
+for divisor in 1, 2, 4, 8, 16, 32:
+ j = m / divisor + 1
+ prod = divisor * j
+ if type(prod) is not long:
+ raise TestFailed, ("expected type(%r) to be long, not %r" %
+ (prod, type(prod)))
+
print '6.4.2 Long integers'
if 12L + 24L != 36L: raise TestFailed, 'long op'
if 12L + (-24L) != -12L: raise TestFailed, 'long op'