[Python-checkins] r60218 - in python/branches/trunk-math: Doc/library/math.rst Lib/test/test_math.py Modules/mathmodule.c

christian.heimes python-checkins at python.org
Wed Jan 23 17:02:55 CET 2008


Author: christian.heimes
Date: Wed Jan 23 17:02:55 2008
New Revision: 60218

Modified:
   python/branches/trunk-math/Doc/library/math.rst
   python/branches/trunk-math/Lib/test/test_math.py
   python/branches/trunk-math/Modules/mathmodule.c
Log:
Make sure pow(0., y) has a constant outcome on all platforms

Modified: python/branches/trunk-math/Doc/library/math.rst
==============================================================================
--- python/branches/trunk-math/Doc/library/math.rst	(original)
+++ python/branches/trunk-math/Doc/library/math.rst	Wed Jan 23 17:02:55 2008
@@ -147,7 +147,11 @@
 
 .. function:: pow(x, y)
 
-   Return ``x**y``.
+   Return ``x**y``. ``1.0**y`` returns *1.0*, even for ``1.0**nan``. ``0**y``
+   returns *0.* for all positive *y* and *0*.
+
+   .. versionchanged:: 2.6
+   The outcome of 1**nan was undefined.
 
 
 .. function:: sqrt(x)

Modified: python/branches/trunk-math/Lib/test/test_math.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_math.py	(original)
+++ python/branches/trunk-math/Lib/test/test_math.py	Wed Jan 23 17:02:55 2008
@@ -321,6 +321,7 @@
             self.assertRaises(ValueError, math.pow, 1, NINF)
         self.assert_(math.isnan(math.pow(NAN, 1)))
         self.assert_(math.isnan(math.pow(2, NAN)))
+        self.assert_(math.isnan(math.pow(0, NAN)))
         self.assertEqual(math.pow(1, NAN), 1)
         self.assertEqual(1**NAN, 1)
         self.assertEqual(1**INF, 1)

Modified: python/branches/trunk-math/Modules/mathmodule.c
==============================================================================
--- python/branches/trunk-math/Modules/mathmodule.c	(original)
+++ python/branches/trunk-math/Modules/mathmodule.c	Wed Jan 23 17:02:55 2008
@@ -328,6 +328,16 @@
 	/* 1^x returns 1., even NaN and INF */
 	if (x == 1.0)
 		return PyFloat_FromDouble(1.);
+	if (x == 0.0) {
+		if (y >= 0.0)
+			return PyFloat_FromDouble(0.);
+		if (Py_IS_NAN(y))
+			return PyFloat_FromDouble(Py_NAN);
+		/* 0 raise to a negative value */
+		errno = EDOM;
+		is_error(x);
+		return NULL;
+	}
 #ifndef __GNUC__ /* Windows et al */
 	if (Py_IS_NAN(x) || Py_IS_NAN(y))
 		return PyFloat_FromDouble(x+y);


More information about the Python-checkins mailing list