Bug 1527007 - Work around Windows fmod bugs r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Thu, 28 Feb 2019 13:22:17 +0000
changeset 461724 865ffd54922df9290d217c75d126da23d0a373c0
parent 461723 3fa94e4ff5dbf92d13b28d4e3e0178f6ec0c8a6b
child 461725 73298bafb7aec4181e2f10516c4d5e21be42e1d4
push id35627
push useropoprus@mozilla.com
push dateThu, 28 Feb 2019 21:44:07 +0000
treeherdermozilla-central@db533ea3d561 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1527007
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527007 - Work around Windows fmod bugs r=jandem 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 */