[Python-3000-checkins] r62611 - in python/branches/py3k: Lib/test/ieee754.txt Lib/test/test_math.py Modules/mathmodule.c
mark.dickinson
python-3000-checkins at python.org
Thu May 1 01:30:58 CEST 2008
Author: mark.dickinson
Date: Thu May 1 01:30:57 2008
New Revision: 62611
Log:
Make floating-point exception error messages slightly more verbose: in
particular, the error message now allows one to distinguish between a
ValueError arising from a singularity (e.g. log(0.)), which would
usually produce +-infinity in non-stop mode, and a ValueError resulting
from an invalid input (e.g. sqrt(-1.)), which would normally produce a
NaN in non-stop mode.
Modified:
python/branches/py3k/Lib/test/ieee754.txt
python/branches/py3k/Lib/test/test_math.py
python/branches/py3k/Modules/mathmodule.c
Modified: python/branches/py3k/Lib/test/ieee754.txt
==============================================================================
--- python/branches/py3k/Lib/test/ieee754.txt (original)
+++ python/branches/py3k/Lib/test/ieee754.txt Thu May 1 01:30:57 2008
@@ -127,31 +127,31 @@
>>> sin(INF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> sin(NINF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> sin(NAN)
nan
>>> cos(INF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> cos(NINF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> cos(NAN)
nan
>>> tan(INF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> tan(NINF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> tan(NAN)
nan
@@ -169,11 +169,11 @@
>>> asin(INF), asin(NINF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> acos(INF), acos(NINF)
Traceback (most recent call last):
...
-ValueError: math domain error
+ValueError: math domain error (invalid argument)
>>> equal(atan(INF), PI/2), equal(atan(NINF), -PI/2)
(True, True)
Modified: python/branches/py3k/Lib/test/test_math.py
==============================================================================
--- python/branches/py3k/Lib/test/test_math.py (original)
+++ python/branches/py3k/Lib/test/test_math.py Thu May 1 01:30:57 2008
@@ -741,9 +741,9 @@
func = getattr(math, fn)
try:
result = func(ar)
- except ValueError:
- message = ("Unexpected ValueError in " +
- "test %s:%s(%r)\n" % (id, fn, ar))
+ except ValueError as exc:
+ message = (("Unexpected ValueError: %s\n " +
+ "in test %s:%s(%r)\n") % (exc.args[0], id, fn, ar))
self.fail(message)
self.ftest("%s:%s(%r)" % (id, fn, ar), result, er)
Modified: python/branches/py3k/Modules/mathmodule.c
==============================================================================
--- python/branches/py3k/Modules/mathmodule.c (original)
+++ python/branches/py3k/Modules/mathmodule.c Thu May 1 01:30:57 2008
@@ -174,18 +174,21 @@
PyFPE_START_PROTECT("in math_1", return 0);
r = (*func)(x);
PyFPE_END_PROTECT(r);
- if (Py_IS_NAN(r)) {
- if (!Py_IS_NAN(x))
- errno = EDOM;
- else
- errno = 0;
+ if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
+ PyErr_SetString(PyExc_ValueError,
+ "math domain error (invalid argument)");
+ return NULL;
}
- else if (Py_IS_INFINITY(r)) {
- if (Py_IS_FINITE(x))
- errno = can_overflow ? ERANGE : EDOM;
- else
- errno = 0;
+ if (Py_IS_INFINITY(r) && Py_IS_FINITE(x)) {
+ if (can_overflow)
+ PyErr_SetString(PyExc_OverflowError,
+ "math range error (overflow)");
+ else
+ PyErr_SetString(PyExc_ValueError,
+ "math domain error (singularity)");
+ return NULL;
}
+ /* on most machines, errno should be 0 at this point */
if (errno && is_error(r))
return NULL;
else
More information about the Python-3000-checkins
mailing list