mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +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
Notes:
sideshowbarker
2024-07-17 20:02:00 +09:00
Author: https://github.com/Panky-codes Commit: https://github.com/SerenityOS/serenity/commit/24c66b84428 Pull-request: https://github.com/SerenityOS/serenity/pull/12198 Reviewed-by: https://github.com/IdanHo
1 changed files with 1 additions and 1 deletions
|
@ -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