Skip to content

Commit

Permalink
Replace mod_inv_5 * mod_inv_5 by explicit value
Browse files Browse the repository at this point in the history
Replace mod_inv_5 * mod_inv_5 by explicit value in order to avoid error C4307: '*': integral constant overflow in VS
  • Loading branch information
florimond-collette committed May 18, 2023
1 parent 9752ab5 commit 7b3c659
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ FMT_INLINE int remove_trailing_zeros(uint32_t& n) noexcept {
FMT_ASSERT(n != 0, "");
// Modular inverse of 5 (mod 2^32): (mod_inv_5 * 5) mod 2^32 = 1.
const uint32_t mod_inv_5 = 0xcccccccd;
const uint32_t mod_inv_25 = mod_inv_5 * mod_inv_5;
const uint32_t mod_inv_25 = 0xc28f5c29; // = mod_inv_5 * mod_inv_5

int s = 0;
while (true) {
Expand Down Expand Up @@ -1163,7 +1163,7 @@ FMT_INLINE int remove_trailing_zeros(uint64_t& n) noexcept {
auto n32 = static_cast<uint32_t>(nm.high() >> (90 - 64));

const uint32_t mod_inv_5 = 0xcccccccd;
const uint32_t mod_inv_25 = mod_inv_5 * mod_inv_5;
const uint32_t mod_inv_25 = 0xc28f5c29; // = mod_inv_5 * mod_inv_5

int s = 8;
while (true) {
Expand All @@ -1184,7 +1184,7 @@ FMT_INLINE int remove_trailing_zeros(uint64_t& n) noexcept {

// If n is not divisible by 10^8, work with n itself.
const uint64_t mod_inv_5 = 0xcccccccccccccccd;
const uint64_t mod_inv_25 = mod_inv_5 * mod_inv_5;
const uint64_t mod_inv_25 = 0x8f5c28f5c28f5c29; // = mod_inv_5 * mod_inv_5

int s = 0;
while (true) {
Expand Down

0 comments on commit 7b3c659

Please sign in to comment.