From 6f5dc695fa41822aef84480ef2d6dcda974e128b Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 5 Oct 2017 18:09:46 +0100 Subject: [PATCH] Add templated versions of CeilDiv and Ceil maths functions --- src/core/math_func.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index df9142462b..2149d1d269 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -318,6 +318,18 @@ static inline uint CeilDiv(uint a, uint b) return (a + b - 1) / b; } +/** + * Computes ceil(a / b) for non-negative a and b (templated). + * @param a Numerator + * @param b Denominator + * @return Quotient, rounded up + */ +template +static inline T CeilDivT(T a, T b) +{ + return (a + b - 1) / b; +} + /** * Computes ceil(a / b) * b for non-negative a and b. * @param a Numerator @@ -329,6 +341,18 @@ static inline uint Ceil(uint a, uint b) return CeilDiv(a, b) * b; } +/** + * Computes ceil(a / b) * b for non-negative a and b (templated). + * @param a Numerator + * @param b Denominator + * @return a rounded up to the nearest multiple of b. + */ +template +static inline T CeilT(T a, T b) +{ + return CeilDivT(a, b) * b; +} + /** * Computes round(a / b) for signed a and unsigned b. * @param a Numerator