diff options
Diffstat (limited to 'common/alnumeric.h')
-rw-r--r-- | common/alnumeric.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/common/alnumeric.h b/common/alnumeric.h index 13e61645..a426763f 100644 --- a/common/alnumeric.h +++ b/common/alnumeric.h @@ -12,6 +12,7 @@ #include <xmmintrin.h> #endif +#include "altraits.h" #include "opthelpers.h" @@ -97,12 +98,20 @@ inline uint32_t NextPowerOf2(uint32_t value) noexcept return value+1; } -/** Round up a value to the next multiple. */ -inline size_t RoundUp(size_t value, size_t r) noexcept -{ - value += r-1; - return value - (value%r); -} +/** + * If the value is not already a multiple of r, round down to the next + * multiple. + */ +template<typename T> +constexpr T RoundDown(T value, al::type_identity_t<T> r) noexcept +{ return value - (value%r); } + +/** + * If the value is not already a multiple of r, round up to the next multiple. + */ +template<typename T> +constexpr T RoundUp(T value, al::type_identity_t<T> r) noexcept +{ return RoundDown(value + r-1, r); } /** |