diff --git a/libs/util/include/psemek/util/bits.hpp b/libs/util/include/psemek/util/bits.hpp index 38d7343b..0e5e5d1e 100644 --- a/libs/util/include/psemek/util/bits.hpp +++ b/libs/util/include/psemek/util/bits.hpp @@ -5,8 +5,15 @@ namespace psemek::util { - // log2 rounded down + template + bool is_pow2(T x) + { + static_assert(std::is_integral_v); + return (x > 0) && ((x & (x - 1)) == 0); + } + + // log2 rounded down template T log2(T x) {