From db06b0df875856968c562d564b595a4e2861144e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 29 Sep 2024 16:57:29 -0700 Subject: [PATCH] Use countl_zero in bigint --- include/fmt/format.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index a2dbdf98..62681924 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2831,10 +2831,8 @@ class bigint { FMT_CONSTEXPR20 void assign_pow10(int exp) { FMT_ASSERT(exp >= 0, ""); if (exp == 0) return *this = 1; - // Find the top bit. - int bitmask = 1; - while (exp >= bitmask) bitmask <<= 1; - bitmask >>= 1; + int bitmask = 1 << (num_bits() - + countl_zero(static_cast(exp)) - 1); // pow(10, exp) = pow(5, exp) * pow(2, exp). First compute pow(5, exp) by // repeated squaring and multiplication. *this = 5;