Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions Modules/_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@
}

#define m_log1p _Py_log1p

static double
_Py_fmod(double x, double y)

Check warning on line 28 in Modules/_math.h

View workflow job for this annotation

GitHub Actions / Address sanitizer

‘_Py_fmod’ defined but not used [-Wunused-function]

Check warning on line 28 in Modules/_math.h

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘_Py_fmod’ defined but not used [-Wunused-function]
{
/* 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this code specific to Windows? For example, use #ifdef _MSC_VER. Move the comment on this part of the code in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we sure that this issue specific only for Windows?

r = copysign(r, x);
}

return r;
}

#define m_fmod _Py_fmod
2 changes: 1 addition & 1 deletion Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ math_fmod_impl(PyObject *module, double x, double y)
if (isinf(y) && isfinite(x))
return PyFloat_FromDouble(x);
errno = 0;
r = fmod(x, y);
r = m_fmod(x, y);
if (isnan(r)) {
if (!isnan(x) && !isnan(y))
errno = EDOM;
Expand Down
Loading