Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add workaround for broken :c:func:`!fmod()` implementations on Windows, that
loose zero sign (e.g. ``fmod(-10, 1)`` returns ``0.0``). Patch by Sergey B
Kirpichev.
9 changes: 9 additions & 0 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,15 @@ math_fmod_impl(PyObject *module, double x, double y)
return PyFloat_FromDouble(x);
errno = 0;
r = fmod(x, y);
#ifdef _MSC_VER
/* Windows (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);
}
#endif
if (Py_IS_NAN(r)) {
if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
errno = EDOM;
Expand Down
Loading