3#include <AH/STL/cstdint>
4#include <AH/STL/type_traits>
13template <u
int8_t N,
class T>
19template <u
int8_t N,
class T>
22 return (
val + (N / 2)) / N;
23 static_assert(std::is_unsigned<T>::value && std::is_integral<T>::value,
24 "This function is only valid for unsigned integers");
29template <u
int8_t N,
class T>
32 T offset =
val >= 0 ? (N / 2) : (-N / 2);
33 return (
val + offset) / N;
39template <u
int8_t N,
class T>
41 : std::conditional<std::is_signed<T>::value, round_div_signed_int<N, T>,
42 round_div_unsigned_int<N, T>>::type {};
46template <u
int8_t N,
class T>
48 : std::conditional<std::is_integral<T>::value, round_div_int<N, T>,
49 round_div_default<N, T>>::type {};
53template <
size_t N,
class T>
#define BEGIN_AH_NAMESPACE
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
T round_div(T val)
Divide a number by N and round the result.
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.