3#include <AH/STL/cstdint>
4#include <AH/STL/type_traits>
16template <uint8_t N, class T>
18 static T
div(T val) {
return val / N; }
22template <u
int8_t N,
class T>
25 return (val + (N / 2)) / N;
26 static_assert(std::is_unsigned<T>::value && std::is_integral<T>::value,
27 "This function is only valid for unsigned integers");
32template <u
int8_t N,
class T>
35 T offset = val >= 0 ? (N / 2) : (-N / 2);
36 return (val + offset) / N;
42template <u
int8_t N,
class T>
44 : std::conditional<std::is_signed<T>::value, round_div_signed_int<N, T>,
45 round_div_unsigned_int<N, T>>::type {};
49template <u
int8_t N,
class T>
51 : std::conditional<std::is_integral<T>::value, round_div_int<N, T>,
52 round_div_default<N, T>>::type {};
56template <
size_t N,
class T>
T round_div(T val)
Divide a number by N and round the result.
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
Divide by N using the default division operator, without explicit rounding This should be used for fl...
Select the right rounding division operator, depending on whether T is an integer or not.
Select the right rounding division operator, depending on whether T is a signed or unsigned integer.
Divide a signed integer by N, rounding the result.
Divide an unsigned integer by N, rounding the result.