23 if constexpr(std::is_unsigned_v<T>)
26 return std::has_single_bit(value);
30 return (value > 0) && !(value & (value - 1));
37template<std::
size_t BASE,
typename T>
40 if constexpr(BASE == 0)
44 else if constexpr(BASE == 1)
48 else if constexpr(BASE == 2)
56 static_assert(BASE <= std::numeric_limits<T>::max());
61 powVal *=
static_cast<T
>(BASE);
64 return powVal == value;
76template<std::
integral T>
77inline T
ceil_div(
const T numerator,
const T denominator)
84 PH_ASSERT_GE(std::numeric_limits<T>::max() - numerator, denominator - 1);
88 return (numerator + (denominator - 1)) / denominator;
95template<std::
integral T>
100 return ceil_div(value, multiple) * multiple;
105template<std::
integral T>
115 PH_ASSERT_GE(std::numeric_limits<T>::max() - value, multiple - 1);
118 return (value + (multiple - 1)) & (0 - multiple);
#define PH_ASSERT_GE(a, b)
Definition assertion.h:67
#define PH_ASSERT_GT(a, b)
Definition assertion.h:61
#define PH_ASSERT(condition)
Definition assertion.h:49
Definition math_basics.h:16
T next_multiple(const T value, const T multiple)
Get the next number that is an integer multiple of multiple. Specifically, get the minimum number x =...
Definition math_basics.h:96
constexpr bool is_power_of(const T value)
Determines whether value is a power-of-BASE number. Checks the equality BASE^n == value,...
Definition math_basics.h:38
constexpr bool is_power_of_2(const T value)
Determines whether value is a power-of-2 number.
Definition math_basics.h:21
T next_power_of_2_multiple(const T value, const T multiple)
Same as next_multiple(T, T) except that multiple must be a power of 2 number.
Definition math_basics.h:106
T ceil_div(const T numerator, const T denominator)
Divide numerator by denominator and round up to integer. Both inputs must be positive integer....
Definition math_basics.h:77