Skip to content

Commit

Permalink
Move workaround to math_fmod_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Sep 17, 2024
1 parent aedcf74 commit fbecd8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
16 changes: 0 additions & 16 deletions Modules/_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,3 @@ _Py_log1p(double x)
}

#define m_log1p _Py_log1p

static double
_Py_fmod(double x, double y)
{
/* Some platforms (e.g. Windows 10 with MSC v.1916) loose sign
for zero result. But C99+ says: "if y is nonzero, the result
has the same sign as x".
*/
double r = fmod(x, y);

if (r == 0.0 && y != 0.0) {
r = copysign(r, x);
}

return r;
}
9 changes: 8 additions & 1 deletion Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,14 @@ math_fmod_impl(PyObject *module, double x, double y)
if (isinf(y) && isfinite(x))
return PyFloat_FromDouble(x);
errno = 0;
r = _Py_fmod(x, y);
r = fmod(x, y);
/* Some platforms (e.g. Windows 10 with MSC v.1916) loose sign
for zero result. But C99+ says: "if y is nonzero, the result
has the same sign as x".
*/
if (r == 0.0 && y != 0.0) {
r = copysign(r, x);
}
if (isnan(r)) {
if (!isnan(x) && !isnan(y))
errno = EDOM;
Expand Down

0 comments on commit fbecd8b

Please sign in to comment.