5#ifndef MLAB_MATHUTILS_HPP
6#define MLAB_MATHUTILS_HPP
21 static_assert(std::is_integral_v<N>);
23 return (n + d - 1) & -d;
25 return (n / d) * d + ((n % d) > 0 ? d : 0);
31 static_assert(std::is_integral_v<N> and std::is_unsigned_v<N>);
33 for (N i = 0; i <
sizeof(N) * 8; ++i) {
35 if (
const N remainder = n & mask; remainder != n) {
36 return {
sizeof(N) * 8 - i - 1, remainder};
constexpr std::pair< N, N > log2_remainder(N n)
Definition mathutils.hpp:30
constexpr N next_multiple(N n, N d)
Definition mathutils.hpp:20