Repository navigation
Fixes #239: Limit the precision again when %g falls back to decimal mode - #240
Conversation
| PRINTING_CHECK("0.0001", ==, sprintf_, buffer, "%.16g", 0.0001); | ||
| PRINTING_CHECK("0.000123", ==, sprintf_, buffer, "%.16g", 0.000123); | ||
| PRINTING_CHECK("0.001000000000000000", ==, sprintf_, buffer, "%#.16g", 0.001); | ||
| } |
There was a problem hiding this comment.
What made you choose to skip the fourth check from the bug, here? Is it redundant?
There was a problem hiding this comment.
Not redundant, it just doesn't pass yet. With the fix %.15g of 0.000338938832258952 prints 0.00033893883225895, while the correct output is 0.000338938832258952: after the fallback that needs 18 decimals, and we only have 17. So a check with the correct value would fail, and checking for the current output would lock in the truncated result.
I could add it commented out, like the beyond-precision checks in tiny_floating_point_values, or check that the output at least starts with 0.000338938832258 (i.e. not 0 anymore). Which would you prefer?
efadbc9 to
07f977d
Compare
|
Tweaking the comments and the testcase after the merge. |
Fixes #239.
When
%gfalls back to decimal mode inprint_exponential_number(), the precision becomesprecision - floored_exp10, which for small values goes pastPRINTF_MAX_SUPPORTED_PRECISION. This limits it again right there, the same wayprint_floating_point()does. Trailing zeros are only added with#, because without it%gdrops trailing zeros, and the zeros put inbufup front wouldn't be dropped.After the change:
The last one is still shorter than glibc's output, because only 17 decimals are available, but before it printed
0.Testing:
avoiding_undefined_behavior. They fail without the change;test_suitepasses with it (581 assertions ondevelop).