Re: [PATCH 6/7] stdio-common: Keep trailing zeros where %#g rounds into a new decade
Matt Turner <[email protected]>
| Newsgroups | gmane.comp.lib.glibc.alpha |
|---|---|
| Message-ID | <CAEdQ38FEyuu8jo+Z_iksh8unQG7Z670AY6jR0Vya_PF+YvFhAA@mail.gmail.com> |
On Fri, Aug 28, 2026 at 7:50 AM Adhemerval Zanella Netto <[email protected]> wrote: > > > > On 24/08/26 19:16, Matt Turner wrote: > > The g and G conversions choose between the f and e styles according to > > the exponent the value has once rounded to the requested number of > > significant digits. Where the value is small enough for the f style but > > rounding then carries into a new decade, printf_fp rewrites the digits > > it has already produced into the e style, recomputing along the way how > > many fractional digits the leading digit now leaves room for. > > > > FRACDIG_MIN, which the alternative form sets to the number of fractional > > digits that have to be retained rather than stripped, was left behind at > > the value computed for the f style. Where the value filled the whole > > integer part that is zero, so all the fractional digits were then > > stripped from a result the '#' flag requires to keep them: > > > > printf ("%#.2g", 99.9) gave "1.e+02" rather than "1.0e+02" > > printf ("%#g", 999999.9) gave "1.e+06" rather than "1.00000e+06" > > > > Update FRACDIG_MIN along with FRACDIG_MAX. Without the alternative form > > nothing retains trailing zeros, so the outcome is unchanged there. > > > > None of the values the conversion tests iterate over round this way, so > > add one that does at a precision they cover. > > > > Tested on x86_64-linux-gnu. > > LGTM, thanks. I think this can be installed independently of the set and > I think we should open a bug report to track it. > > Reviewed-by: Adhemerval Zanella <[email protected]> Thanks, feel free to peel off patches from this series and merge them independently. I've filed a bug (https://sourceware.org/bugzilla/show_bug.cgi?id=34578) for this issue.