Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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,2 @@
Add workaround for broken :c:func:`!fmod()` implementations (e.g. on
Windows), that loose zero sign. Patch by Sergey B Kirpichev.
7 changes: 7 additions & 0 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,13 @@ math_fmod_impl(PyObject *module, double x, double y)
return PyFloat_FromDouble(x);
errno = 0;
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
Loading