From f876c03086feb94584fabeaf8941282d9dd88770 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 18 Feb 2016 17:33:37 +0000 Subject: [PATCH] Fix incorrect rounding in frames_round() and frames_ceil() when passed integer parameters. --- src/lib/dcpomatic_time.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 90e79de0a..3658320c8 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -132,7 +132,11 @@ public: template 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 @@ -142,7 +146,11 @@ public: template 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 */ -- 2.30.2