The BSD printf flubbs floating, especially when the number ends
with all zeros. The root problem is that one digit is printed
explicitly; any remaining digits need to be printed too - but
only if they aren't zero since the zero fill will take care of
them.
If there is only one digit, to print (e.g. 1.000) the calculation
handling the remaining digits comes up with -1 and, well, one gets
what they deserve.
The fix is easy - don't try to output a negative number of digits.
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
buf[0] = *cp++;
buf[1] = *decimal_point;
PRINT(buf, 2);
- PRINT(cp, ndig - 1);
+ if (ndig > 0) {
+ PRINT(cp, ndig - 1);
+ }
PAD(prec - ndig, zeroes);
} else { /* XeYYY */
PRINT(cp, 1);