From 82623d83c50048c5b74771e2545886df6a9042f1 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 22 Sep 2026 13:57:31 -0400 Subject: [PATCH] Avoid right-shifting a negative value in subnormal_ties_possible() --- include/fast_float/float_common.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 76d94b3..bcef8d8 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -1117,11 +1117,12 @@ inline constexpr bool binary_format::fast_path_can_overflow() { // A subnormal needs w * 10^q < 2^(minimum_exponent() + 1), so q is at most // (minimum_exponent() + 1) * log10(2), with 1233/4096 < log10(2). Only -// std::float16_t has such q in its round-to-even range. +// std::float16_t has such q in its round-to-even range. We compare +// 4096 * q with (minimum_exponent() + 1) * 1233 to avoid right-shifting a +// negative value (implementation-defined before C++20). template inline constexpr bool binary_format::subnormal_ties_possible() { - return min_exponent_round_to_even() <= - (((minimum_exponent() + 1) * 1233) >> 12); + return min_exponent_round_to_even() * 4096 <= (minimum_exponent() + 1) * 1233; } template <>