Skip to content

Commit

Permalink
Avoid unsigned overflow when computing the full-bit mask
Browse files Browse the repository at this point in the history
  • Loading branch information
jk-jeon committed Apr 2, 2024
1 parent 000eb42 commit 9be45d3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/dragonbox/dragonbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ namespace jkj {
// Shift the obtained signed significand bits to the left by 1 to remove the sign bit.
static constexpr carrier_uint remove_sign_bit_and_shift(carrier_uint u) noexcept {
constexpr auto mask =
carrier_uint(((carrier_uint(1) << (Format::total_bits - 1)) << 1) - 1u);
carrier_uint((((carrier_uint(1) << (Format::total_bits - 1)) - 1u) << 1) | 1u);
return carrier_uint((carrier_uint(u) << 1) & mask);
}

Expand Down Expand Up @@ -411,7 +411,7 @@ namespace jkj {
}
static constexpr bool has_all_zero_significand_bits(carrier_uint u) noexcept {
constexpr auto mask =
carrier_uint(((carrier_uint(1) << (Format::total_bits - 1)) << 1) - 1u);
carrier_uint((((carrier_uint(1) << (Format::total_bits - 1)) - 1u) << 1) | 1u);
return ((u << 1) & mask) == 0;
}
static constexpr bool has_even_significand_bits(carrier_uint u) noexcept {
Expand Down

0 comments on commit 9be45d3

Please sign in to comment.