diff --git a/js/src/jslibmath.h b/js/src/jslibmath.h index e8aaaf5d9ee8..77be814b1409 100644 --- a/js/src/jslibmath.h +++ b/js/src/jslibmath.h @@ -36,7 +36,16 @@ inline double NumberMod(double a, double b) { if (b == 0) { return JS::GenericNaN(); } - return fmod(a, b); + double r = fmod(a, b); +#if defined(XP_WIN) + // Some versions of Windows (Win 10 v1803, v1809) miscompute the sign of zero + // results from fmod. The sign should match the sign of the LHS. This bug + // only affects 64-bit builds. See bug 1527007. + if (mozilla::IsPositiveZero(r) && mozilla::IsNegative(a)) { + return -0.0; + } +#endif + return r; } } // namespace js