summaryrefslogtreecommitdiff
path: root/Lib/test/test_pow.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-05-24 20:18:24 +0000
committerTim Peters <tim.peters@gmail.com>2003-05-24 20:18:24 +0000
commite87568dd9a8a1ccdcc05398c19ab45243b1979b5 (patch)
tree5516eedc9948940cbd255179e81017ae54bf6433 /Lib/test/test_pow.py
parent0ed39577ddcc7dadb642b316eb90e91b60bacdcc (diff)
downloadcpython-git-e87568dd9a8a1ccdcc05398c19ab45243b1979b5.tar.gz
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/test_pow.py')
-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 2c86b09667..c6ab218eb8 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)