Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify math_1, like other functions
Now exception messages kept in is_error().  This improve
coverage for L1007.
  • Loading branch information
skirpichev committed Apr 8, 2023
commit 9c32ae022f07ea90892175a2d7f5c777621be0e0
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))
Comment thread
skirpichev marked this conversation as resolved.
Outdated
return NULL;

return PyFloat_FromDouble(r);
}

Expand Down