[Python-checkins] python/dist/src/Lib/test test_pow.py,1.18,1.19

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sat, 24 May 2003 13:18:26 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv23294/Lib/test

Modified Files:
	test_pow.py 
Log Message:
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.


Index: test_pow.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pow.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** test_pow.py	1 May 2003 17:45:45 -0000	1.18
--- test_pow.py	24 May 2003 20:18:24 -0000	1.19
***************
*** 102,105 ****
--- 102,122 ----
          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():