Bug 1222866: P1. Round second to closest microseconds. r=gerald.
☠☠ backed out by 96d02c2defe1 ☠ ☠
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 20 Nov 2015 11:06:22 +1100
changeset 273436 002714e2ccbac1d3bd2a73f86a3fc2eef277d1a0
parent 273435 08a4d2e0ad799fe03c77f1d79d11cfa5c430c621
child 273437 74caf0456e1e12c6e531a6d9c614f92109e5f815
push id68280
push userjyavenard@mozilla.com
push dateFri, 20 Nov 2015 04:43:31 +0000
treeherdermozilla-inbound@74caf0456e1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1222866
milestone45.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 1222866: P1. Round second to closest microseconds. r=gerald. Due to the internal double representation as per IEEE 754, during conversion the use of ints would have rounded down our value.
dom/media/TimeUnits.h
--- a/dom/media/TimeUnits.h
+++ b/dom/media/TimeUnits.h
@@ -88,17 +88,19 @@ struct Microseconds {
 class TimeUnit final {
 public:
   static TimeUnit FromSeconds(double aValue) {
     MOZ_ASSERT(!IsNaN(aValue));
 
     if (mozilla::IsInfinite<double>(aValue)) {
       return FromInfinity();
     }
-    double val = aValue * USECS_PER_S;
+    // Due to internal double representation, this
+    // operation is not commutative, do not attempt to simplify.
+    double val = (aValue + .0000005) * USECS_PER_S;
     if (val >= double(INT64_MAX)) {
       return FromMicroseconds(INT64_MAX);
     } else if (val <= double(INT64_MIN)) {
       return FromMicroseconds(INT64_MIN);
     } else {
       return FromMicroseconds(int64_t(val));
     }
   }