Fix incorrect rounding in frames_round() and frames_ceil() when passed integer parame...
authorCarl Hetherington <cth@carlh.net>
Thu, 18 Feb 2016 17:33:37 +0000 (17:33 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 18 Feb 2016 17:33:37 +0000 (17:33 +0000)
src/lib/dcpomatic_time.h

index 90e79de0a7b4cec45cee0a495d63554f2a6fa2c6..3658320c85a49d343b9099ea55a09d4cc8a072c1 100644 (file)
@@ -132,7 +132,11 @@ public:
 
        template <typename T>
        int64_t frames_round (T r) const {
-               return llrint (_t * r / HZ);
+               /* We must cast to double here otherwise if T is integer
+                  the calculation will round down before we get the chance
+                  to llrint().
+               */
+               return llrint (_t * double(r) / HZ);
        }
 
        template <typename T>
@@ -142,7 +146,11 @@ public:
 
        template <typename T>
        int64_t frames_ceil (T r) const {
-               return ceil (_t * r / HZ);
+               /* We must cast to double here otherwise if T is integer
+                  the calculation will round down before we get the chance
+                  to ceil().
+               */
+               return ceil (_t * double(r) / HZ);
        }
 
        /** @param r Frames per second */