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
Revert "Simplify math_1, like other functions"
This reverts commit 9c32ae0.
  • Loading branch information
skirpichev committed Sep 3, 2023
commit 796bdca44c9662d27353e7281bd7ecf6a5f9e0e0
17 changes: 12 additions & 5 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,17 +962,24 @@ 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))
errno = EDOM;
if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
PyErr_SetString(PyExc_ValueError,
"math domain error"); /* invalid arg */
return NULL;
}
if (Py_IS_INFINITY(r) && Py_IS_FINITE(x)) {
if (can_overflow)
errno = ERANGE;
PyErr_SetString(PyExc_OverflowError,
"math range error"); /* overflow */
else
errno = EDOM;
PyErr_SetString(PyExc_ValueError,
"math domain error"); /* singularity */
return NULL;
}
if (errno && is_error(r))
if (Py_IS_FINITE(r) && errno && is_error(r))
/* this branch unnecessary on most platforms */
return NULL;

return PyFloat_FromDouble(r);
}

Expand Down