Fix stdio fmt of "%.0e" and "%.0g" - #544
Conversation
|
Is there a specific spec of printf cosmo is trying to follow? The failing tests below from fmt_test.c in glibc prints for those tests. My interpretation of the The "%g" patch currently included causes 10 and -10 to match the glibc behavior of encoding them as |
Glibc is the gold standard of C libraries. Anything that helps us be closer to Glibc in terms of behavior would be very welcome. If we have tests that specify a behavior that's inconsistent with Glibc, then our tests are wrong. Many of them were borrowed from Paland's printf() implementation which was intended to be a simple solution for embedded systems. We've modified our implementation a lot since then to bring ourselves into closer conformance. For instance, a lot of the double formatting code in our printf() implementation was borrowed from the dtoa authors. Since you're already a contributor, please ping me when this is ready to merge. Then I'll approve it. |
|
@jart Thanks for the quick reviews. I fixed the %g tests to match glibc and added more. LGTM. |
Fixes #543
"%.0e"was fixed by always using dtoa mode 2: max(1,ndigits) significant digits so the number will still be rounded even if no decimal places will be printed, the change should only change behavior when precision is 0.The fix to
"%.0g"is similar, according toman 3 printf"if the precision is zero, it is treated as 1", so perc is now rounded up to 1 instead of 0 if necessary. This also leads to always using dtoa mode 2.EDIT: Changing this to WIP as "%.0g", 10 and "%.0g", -10. appears to be failing.
EDIT2: Not sure if the behavior required by tests is desired, see next comment.