mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-06 16:09:30 +00:00
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:
parent
0f010cee02
commit
24c66b8442
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue