Skip to content

Commit

Permalink
Simplify math_1, like other functions
Browse files Browse the repository at this point in the history
Now exception messages kept in is_error().  This improve
coverage for L1007.
  • Loading branch information
skirpichev committed Apr 8, 2023
1 parent 86aee3c commit 9c32ae0
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,24 +990,16 @@ math_1(PyObject *arg, double (*func) (double), int can_overflow)
return NULL;
errno = 0;
r = (*func)(x);
if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
PyErr_SetString(PyExc_ValueError,
"math domain error"); /* invalid arg */
return NULL;
}
if (Py_IS_NAN(r) && !Py_IS_NAN(x))
errno = EDOM;
if (Py_IS_INFINITY(r) && Py_IS_FINITE(x)) {
if (can_overflow)
PyErr_SetString(PyExc_OverflowError,
"math range error"); /* overflow */
errno = ERANGE;
else
PyErr_SetString(PyExc_ValueError,
"math domain error"); /* singularity */
return NULL;
errno = EDOM;
}
if (Py_IS_FINITE(r) && errno && is_error(r))
/* this branch unnecessary on most platforms */
if (errno && is_error(r))
return NULL;

return PyFloat_FromDouble(r);
}

Expand Down

0 comments on commit 9c32ae0

Please sign in to comment.