Skip to content

Commit

Permalink
More efficient (for finite x) handling of special cases in math.modf
Browse files Browse the repository at this point in the history
Rewrite changes in python#102523
  • Loading branch information
skirpichev committed Oct 6, 2023
1 parent 96f99cd commit 3df127e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2190,10 +2190,12 @@ math_modf_impl(PyObject *module, double x)
double y;
/* some platforms don't do the right thing for NaNs and
infinities, so we take care of special cases directly. */
if (Py_IS_INFINITY(x))
return Py_BuildValue("(dd)", copysign(0., x), x);
else if (Py_IS_NAN(x))
return Py_BuildValue("(dd)", x, x);
if (!Py_IS_FINITE(x)) {
if (Py_IS_INFINITY(x))
return Py_BuildValue("(dd)", copysign(0., x), x);
else
return Py_BuildValue("(dd)", x, x);
}

errno = 0;
x = modf(x, &y);
Expand Down

0 comments on commit 3df127e

Please sign in to comment.