Bug 1222866 - P1. Round second to closest microseconds. r=gerald, a=lizzard
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 20 Nov 2015 11:06:22 +1100
changeset 291630 8a55efc59eae6de1e53d240cdb81c37e8816c5c1
parent 291629 ffdc3e33fc9ebab045a21dbb444b441b9756b7b2
child 291631 124aaf8a8940cf68c741f7185b317c2afd0516b9
push id8757
push usercbook@mozilla.com
push dateTue, 24 Nov 2015 11:13:56 +0000
treeherdermozilla-aurora@124aaf8a8940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, lizzard
bugs1222866
milestone44.0a2
Bug 1222866 - P1. Round second to closest microseconds. r=gerald, a=lizzard 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));
     }
   }