Repository navigation
Fix high-precision floating-point formatting - #4960
Conversation
| #if FMT_USE_CONSTEVAL | ||
| // Use the builtin directly to avoid C++ runtime dependencies at -O0. | ||
| if (__builtin_is_constant_evaluated()) | ||
| return std::allocator<T>().allocate(n); |
There was a problem hiding this comment.
Let's use new/delete and avoid conditional dependency on <memory>.
There was a problem hiding this comment.
Switched constexpr allocation to new[]/delete[] and removed the added <memory> include. The growth loop still starts element lifetimes for standard and custom allocators; local GCC and Clang constexpr checks pass.
| EXPECT_EQ(fmt::format("{0:.6}", "123456\xad"), "123456"); | ||
| } | ||
|
|
||
| TEST(format_test, high_precision_trailing_zeros) { |
There was a problem hiding this comment.
Could we trim these tests a bit? There seems to be quite a bit of overlapping coverage, especially around sign variants, nearby precisions, and simple zero/0.5 cases.
There was a problem hiding this comment.
Trimmed the nearby precision and sign variants, plus the repeated long double zero/0.5 cases. The remaining tests cover trailing zeros, padding, bounded output, and extreme exponents.
|
Thanks for the fix! |
Fix high-precision floating-point formatting that drops requested trailing zeros or truncates digits in the Dragon fallback. For example, formatting
0.0625with{:.768f}now preserves all 768 fractional places.The fallback bounds digit generation using the value's exponent and significand, while the fast double path keeps its existing limit. Fixed and alternate-general formatting then append the requested zeros. Constant-evaluated buffer growth allocates usable storage and starts element lifetimes before writing to it.
Regression tests cover trailing zeros, bounded output, long double, and high-precision constexpr formatting. The affected C++20 format and compile suites pass on Linux. Additional GCC/Clang checks cover constexpr output and unchanged runtime link requirements; x87 and binary128 results were checked against an integer-arithmetic oracle.
MSVC and module builds have not been run locally.