Fix a bug where printf was erroneously printing a decimal point for

%f and sufficiently short %g specifiers where the precision was
explicitly zero, no '#' flag was specified, and the floating point
argument was > 0 and <= 0.5.  While at it, add some comments to better
explain the relevant bits of code.

Noticed by:	Christoph Kukulies <kuku@physik.rwth-aachen.de>
This commit is contained in:
David Schultz 2003-04-14 11:24:53 +00:00
parent bb342a3713
commit 81ae2e9a4d

View File

@ -928,12 +928,14 @@ fp_begin:
if (prec > 1 || flags & ALT) if (prec > 1 || flags & ALT)
++size; ++size;
} else { } else {
if (expt > 0) { /* space for digits before decimal point */
if (expt > 0)
size = expt; size = expt;
if (prec || flags & ALT) else /* "0" */
size += prec + 1; size = 1;
} else /* "0.X" */ /* space for decimal pt and following digits */
size = prec + 2; if (prec || flags & ALT)
size += prec + 1;
if (grouping && expt > 0) { if (grouping && expt > 0) {
/* space for thousands' grouping */ /* space for thousands' grouping */
nseps = nrepeats = 0; nseps = nrepeats = 0;
@ -1163,9 +1165,9 @@ number: if ((dprec = prec) >= 0)
} else { /* glue together f_p fragments */ } else { /* glue together f_p fragments */
if (!expchar) { /* %[fF] or sufficiently short %[gG] */ if (!expchar) { /* %[fF] or sufficiently short %[gG] */
if (expt <= 0) { if (expt <= 0) {
buf[0] = '0'; PRINT(zeroes, 1);
buf[1] = *decimal_point; if (prec || flags & ALT)
PRINT(buf, 2); PRINT(decimal_point, 1);
PAD(-expt, zeroes); PAD(-expt, zeroes);
/* already handled initial 0's */ /* already handled initial 0's */
prec += expt; prec += expt;