From 24c66b8442881ee037271d0c3cfb315cef0f3135 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Sat, 29 Jan 2022 15:26:43 +0530 Subject: [PATCH] AK: Fix log2 calculation for Integer For a `N` bit integer X, the log2 calculation should be as follows: (N - 1) - ctz(X) --- AK/Math.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AK/Math.h b/AK/Math.h index ed6d91c367..469cc7e5ec 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -298,7 +298,7 @@ constexpr T log2(T x) template constexpr T log2(T x) { - return x ? 8 * sizeof(T) - count_leading_zeroes(static_cast>(x)) : 0; + return x ? (8 * sizeof(T) - 1) - count_leading_zeroes(static_cast>(x)) : 0; } template