Skip to content

Commit

Permalink
Fix errors in countr_zero (see #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jk-jeon committed Jan 8, 2021
1 parent 9e93758 commit aa9904b
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions include/dragonbox/dragonbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,39 @@ namespace jkj::dragonbox {
}
#else
#define JKJ_HAS_COUNTR_ZERO_INTRINSIC 0
int count = int(value_bits<UInt>);

int count;
auto n32 = std::uint32_t(n);

if constexpr (value_bits<UInt> > 32) {
if (n32 != 0) {
count = 31;
}
else {
n32 = std::uint32_t(n >> 32);
if constexpr (value_bits<UInt> == 64) {
if (n32 != 0) {
count = 63;
}
else {
return 64;
}
}
else {
count = value_bits<UInt>;
}
}
}
else {
if constexpr (value_bits<UInt> == 32) {
if (n32 != 0) {
count -= 1;
count = 31;
}
else {
return 32;
}
}
else {
count = value_bits<UInt>;
}
}
if constexpr (value_bits<UInt> > 16) {
Expand Down

0 comments on commit aa9904b

Please sign in to comment.