[Python-checkins] r76483 - in python/trunk: Lib/test/test_float.py Python/bltinmodule.c
mark.dickinson
python-checkins at python.org
Tue Nov 24 11:54:59 CET 2009
Author: mark.dickinson
Date: Tue Nov 24 11:54:58 2009
New Revision: 76483
Log:
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
Modified:
python/trunk/Lib/test/test_float.py
python/trunk/Python/bltinmodule.c
Modified: python/trunk/Lib/test/test_float.py
==============================================================================
--- python/trunk/Lib/test/test_float.py (original)
+++ python/trunk/Lib/test/test_float.py Tue Nov 24 11:54:58 2009
@@ -367,6 +367,11 @@
self.assertEqual(round(-INF, n), -INF)
self.assertTrue(math.isnan(round(NAN, n)))
+ self.assertRaises(TypeError, round, INF, 0.0)
+ self.assertRaises(TypeError, round, -INF, 1.0)
+ self.assertRaises(TypeError, round, NAN, "ceci n'est pas un integer")
+ self.assertRaises(TypeError, round, -0.0, 1j)
+
def test_large_n(self):
for n in [324, 325, 400, 2**31-1, 2**31, 2**32, 2**100]:
self.assertEqual(round(123.456, n), 123.456)
Modified: python/trunk/Python/bltinmodule.c
==============================================================================
--- python/trunk/Python/bltinmodule.c (original)
+++ python/trunk/Python/bltinmodule.c Tue Nov 24 11:54:58 2009
@@ -2130,10 +2130,6 @@
kwlist, &x, &o_ndigits))
return NULL;
- /* nans, infinities and zeros round to themselves */
- if (!Py_IS_FINITE(x) || x == 0.0)
- return PyFloat_FromDouble(x);
-
if (o_ndigits == NULL) {
/* second argument defaults to 0 */
ndigits = 0;
@@ -2145,6 +2141,10 @@
return NULL;
}
+ /* nans, infinities and zeros round to themselves */
+ if (!Py_IS_FINITE(x) || x == 0.0)
+ return PyFloat_FromDouble(x);
+
/* Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x
always rounds to itself. For ndigits < NDIGITS_MIN, x always
rounds to +-0.0. Here 0.30103 is an upper bound for log10(2). */
More information about the Python-checkins
mailing list