Bug 1527007 - Work around Windows fmod bugs r=jandem a=lizzard
authorTed Campbell <tcampbell@mozilla.com>
Thu, 28 Feb 2019 13:22:17 +0000
changeset 516227 d53e3a3bef07479fff7243d33d13f6ac38554ebb
parent 516226 bdc420ea17d6f2688cc1de7f433b5b2330b11983
child 516228 02370e541eb933f3798c3c6fe22be8cc89cf9476
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, lizzard
bugs1527007
milestone66.0
Bug 1527007 - Work around Windows fmod bugs r=jandem a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D21407
js/src/jslibmath.h
--- a/js/src/jslibmath.h
+++ b/js/src/jslibmath.h
@@ -31,14 +31,23 @@ inline double NumberDiv(double a, double
   return a / b;
 }
 
 inline double NumberMod(double a, double b) {
   AutoUnsafeCallWithABI unsafe(UnsafeABIStrictness::AllowPendingExceptions);
   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
 
 #endif /* jslibmath_h */