summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-05-24 20:18:24 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-05-24 20:18:24 (GMT)
commite87568dd9a8a1ccdcc05398c19ab45243b1979b5 (patch)
tree5516eedc9948940cbd255179e81017ae54bf6433 /Lib/test
parent0ed39577ddcc7dadb642b316eb90e91b60bacdcc (diff)
downloadcpython-e87568dd9a8a1ccdcc05398c19ab45243b1979b5.zip
cpython-e87568dd9a8a1ccdcc05398c19ab45243b1979b5.tar.gz
cpython-e87568dd9a8a1ccdcc05398c19ab45243b1979b5.tar.bz2
SF bug 705231: Assertion failed, python aborts.
float_pow(): Don't let the platform pow() raise -1.0 to an integer power anymore; at least glibc gets it wrong in some cases. Note that math.pow() will continue to deliver wrong (but platform-native) results in such cases.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_pow.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_pow.py b/Lib/test/test_pow.py
index 2c86b09..c6ab218 100644
--- a/Lib/test/test_pow.py
+++ b/Lib/test/test_pow.py
@@ -101,6 +101,23 @@ class PowTest(unittest.TestCase):
return None
None ** TestRpow() # Won't fail when __rpow__ invoked. SF bug #643260.
+ def test_bug705231(self):
+ # -1.0 raised to an integer should never blow up. It did if the
+ # platform pow() was buggy, and Python didn't worm around it.
+ eq = self.assertEquals
+ a = -1.0
+ eq(pow(a, 1.23e167), 1.0)
+ eq(pow(a, -1.23e167), 1.0)
+ for b in range(-10, 11):
+ eq(pow(a, float(b)), b & 1 and -1.0 or 1.0)
+ for n in range(0, 100):
+ fiveto = float(5 ** n)
+ # For small n, fiveto will be odd. Eventually we run out of
+ # mantissa bits, though, and thereafer fiveto will be even.
+ expected = fiveto % 2.0 and -1.0 or 1.0
+ eq(pow(a, fiveto), expected)
+ eq(pow(a, -fiveto), expected)
+ eq(expected, 1.0) # else we didn't push fiveto to evenness
def test_main():
test.test_support.run_unittest(PowTest)