diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-02-18 17:33:37 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-02-18 17:33:37 +0000 |
| commit | f876c03086feb94584fabeaf8941282d9dd88770 (patch) | |
| tree | 1aed7ca7722d8462267fb165c2ef2b2da559e363 /src | |
| parent | 48e56e1c8b9343ae84ddcda8bab795f763d2d544 (diff) | |
Fix incorrect rounding in frames_round() and frames_ceil() when passed integer parameters.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/dcpomatic_time.h | 12 |
1 files 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 <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 */ |
