diff --git a/BAN/include/BAN/Math.h b/BAN/include/BAN/Math.h index 91a7a558df..e87012871a 100644 --- a/BAN/include/BAN/Math.h +++ b/BAN/include/BAN/Math.h @@ -59,6 +59,17 @@ namespace BAN::Math return (value & (value - 1)) == 0; } + template + requires is_same_v || is_same_v || is_same_v + inline constexpr T ilog2(T value) + { + if constexpr(is_same_v) + return sizeof(T) * 8 - __builtin_clz(value) - 1; + if constexpr(is_same_v) + return sizeof(T) * 8 - __builtin_clzl(value) - 1; + return sizeof(T) * 8 - __builtin_clzll(value) - 1; + } + template inline constexpr T log2(T value) {