From aa9904b7c41a266f70ee627d639de9af109e60e6 Mon Sep 17 00:00:00 2001 From: Junekey Jeon Date: Fri, 8 Jan 2021 12:01:16 -0800 Subject: [PATCH] Fix errors in countr_zero (see #11) --- include/dragonbox/dragonbox.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/include/dragonbox/dragonbox.h b/include/dragonbox/dragonbox.h index a744668..937b058 100644 --- a/include/dragonbox/dragonbox.h +++ b/include/dragonbox/dragonbox.h @@ -310,18 +310,39 @@ namespace jkj::dragonbox { } #else #define JKJ_HAS_COUNTR_ZERO_INTRINSIC 0 - int count = int(value_bits); - + int count; auto n32 = std::uint32_t(n); + if constexpr (value_bits > 32) { if (n32 != 0) { count = 31; } else { n32 = std::uint32_t(n >> 32); + if constexpr (value_bits == 64) { + if (n32 != 0) { + count = 63; + } + else { + return 64; + } + } + else { + count = value_bits; + } + } + } + else { + if constexpr (value_bits == 32) { if (n32 != 0) { - count -= 1; + count = 31; } + else { + return 32; + } + } + else { + count = value_bits; } } if constexpr (value_bits > 16) {