summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2008-04-30 23:30:57 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2008-04-30 23:30:57 (GMT)
commita0de26c3427b63efcd0a678c5d686b4df9f105e4 (patch)
tree359d9467600c47eb14c3a1926e6a9ebda7720bb3 /Modules/mathmodule.c
parent3cbf15f07a72c1dad2196975448ce18725f18c08 (diff)
downloadcpython-a0de26c3427b63efcd0a678c5d686b4df9f105e4.zip
cpython-a0de26c3427b63efcd0a678c5d686b4df9f105e4.tar.gz
cpython-a0de26c3427b63efcd0a678c5d686b4df9f105e4.tar.bz2
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.
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 3cf1133..aa38691 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -174,18 +174,21 @@ math_1_to_whatever(PyObject *arg, double (*func) (double),
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