mirror of
https://github.com/fmtlib/fmt.git
synced 2026-07-30 08:16:31 +08:00
Guard fast decimal path on bit width instead of byte size
Use num_bits<UInt>() == 32 instead of sizeof(UInt) == 4 in do_format_decimal. The magic-number two-digit algorithm requires exactly 32 value bits, so this is more precise on platforms where CHAR_BIT != 8 and is consistent with existing num_bits<T>() usage.
This commit is contained in:
parent
9d13c41ce6
commit
7077b016cc
@ -1234,7 +1234,7 @@ FMT_CONSTEXPR20 auto do_format_decimal(Char* out, UInt value, int size)
|
||||
unsigned n = to_unsigned(size);
|
||||
while (value >= 100) {
|
||||
n -= 2;
|
||||
if (!is_constant_evaluated() && sizeof(UInt) == 4) {
|
||||
if (!is_constant_evaluated() && num_bits<UInt>() == 32) {
|
||||
auto p = value * static_cast<uint64_t>((1ull << 39) / 100 + 1);
|
||||
write2digits_i(out + n, p >> (39 - 7) & ((1 << 7) - 1));
|
||||
value = static_cast<UInt>(p >> 39) +
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user