Skip to content

Commit 3df127e

Browse files
committed
More efficient (for finite x) handling of special cases in math.modf
Rewrite changes in python#102523
1 parent 96f99cd commit 3df127e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Modules/mathmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,10 +2190,12 @@ math_modf_impl(PyObject *module, double x)
21902190
double y;
21912191
/* some platforms don't do the right thing for NaNs and
21922192
infinities, so we take care of special cases directly. */
2193-
if (Py_IS_INFINITY(x))
2194-
return Py_BuildValue("(dd)", copysign(0., x), x);
2195-
else if (Py_IS_NAN(x))
2196-
return Py_BuildValue("(dd)", x, x);
2193+
if (!Py_IS_FINITE(x)) {
2194+
if (Py_IS_INFINITY(x))
2195+
return Py_BuildValue("(dd)", copysign(0., x), x);
2196+
else
2197+
return Py_BuildValue("(dd)", x, x);
2198+
}
21972199

21982200
errno = 0;
21992201
x = modf(x, &y);

0 commit comments

Comments
 (0)