[PATCH] printf: Enable grouping decimal values

Corinna Vinschen vinschen@redhat.com
Thu Feb 4 20:21:00 GMT 2010

On Feb  4 21:12, Corinna Vinschen wrote:
> On Feb  4 13:30, Jeff Johnston wrote:
> > On 01/02/10 03:47 PM, Corinna Vinschen wrote:
> > >Hi,
> > >
> > >the below patch is derived from NetBSD code.  It enables printf/wprintf
> > >grouping using the thousands' grouping character from the locale
> > >information when the ' (single quote) flag character has been specified
> > >in decimal conversions (i, d, u, f, F, g, G), as specified by POSIX-1.2008.
> > 
> > This is a tough patch to review because of all the format changes
> > and ifdefs in the patch itself.
> > 
> > I did notice one spot where the size is being calculated and the
> > grouping ptr is moved to do this calculation.  I can't see anywhere
> > where you are resetting grouping before the output is written.  This
> > seems like a mistake, but perhaps I am missing something.
> That's correct.  In case of float values there are two runs, one to
> compute the size, the number of lead digits, the number of required
> separators and and the number of repetitions for the leftmost grouping.
> While doing that, the grouping pointer is moved to the end of the
> grouping string:
> [...]
> Later, when the float value is actually printed, the grouping pointer
> moves backward again, depending on the number of repetitions and
> actual number of explicit groupings:
> [...]

One more point: Consider that the grouping string defines the grouping
from right to left, while the printing goes from left to right.  That
should explain why moving the grouping pointer backwards while printing
makes sense.


Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

More information about the Newlib mailing list