Mercurial > cpython-lru_cache-weakref
diff Modules/mathmodule.c @ 46616:3f2117d3271f
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.
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Wed, 30 Apr 2008 23:30:57 +0000 |
| parents | ec48490b969a |
| children | e42fe19ba6fd |
line wrap: on
line diff
--- a/Modules/mathmodule.c Wed Apr 30 22:36:24 2008 +0000 +++ b/Modules/mathmodule.c Wed Apr 30 23:30:57 2008 +0000 @@ -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
