Skip to content

Commit 9c32ae0

Browse files
committed
Simplify math_1, like other functions
Now exception messages kept in is_error(). This improve coverage for L1007.
1 parent 86aee3c commit 9c32ae0

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

Modules/mathmodule.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -990,24 +990,16 @@ math_1(PyObject *arg, double (*func) (double), int can_overflow)
990990
return NULL;
991991
errno = 0;
992992
r = (*func)(x);
993-
if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
994-
PyErr_SetString(PyExc_ValueError,
995-
"math domain error"); /* invalid arg */
996-
return NULL;
997-
}
993+
if (Py_IS_NAN(r) && !Py_IS_NAN(x))
994+
errno = EDOM;
998995
if (Py_IS_INFINITY(r) && Py_IS_FINITE(x)) {
999996
if (can_overflow)
1000-
PyErr_SetString(PyExc_OverflowError,
1001-
"math range error"); /* overflow */
997+
errno = ERANGE;
1002998
else
1003-
PyErr_SetString(PyExc_ValueError,
1004-
"math domain error"); /* singularity */
1005-
return NULL;
999+
errno = EDOM;
10061000
}
1007-
if (Py_IS_FINITE(r) && errno && is_error(r))
1008-
/* this branch unnecessary on most platforms */
1001+
if (errno && is_error(r))
10091002
return NULL;
1010-
10111003
return PyFloat_FromDouble(r);
10121004
}
10131005

0 commit comments

Comments
 (0)