AK: Fix log2 calculation for Integer

For a `N` bit integer X, the log2 calculation should be as follows:
(N - 1) - ctz(X)
This commit is contained in:
Pankaj Raghav 2022-01-29 15:26:43 +05:30 committed by Idan Horowitz
parent 0f010cee02
commit 24c66b8442
Notes: sideshowbarker 2024-07-17 20:02:00 +09:00

View file

@ -298,7 +298,7 @@ constexpr T log2(T x)
template<Integral T>
constexpr T log2(T x)
{
return x ? 8 * sizeof(T) - count_leading_zeroes(static_cast<MakeUnsigned<T>>(x)) : 0;
return x ? (8 * sizeof(T) - 1) - count_leading_zeroes(static_cast<MakeUnsigned<T>>(x)) : 0;
}
template<FloatingPoint T>