Mail Archives: djgpp/1998/03/02/09:30:32
I've also noticed a couple of other differences in printf between DJGPP
and Linux:
1. printf("%9.6g",99999.9999);
displays '100000.' in Linux but '100000.0' in DJGPP.
I think Linux may be correct here but I haven't fixed this one.
2. printf("%1.1f",0.00123);
displays '-0.0' in Linux but '0.0' in DJGPP.
I hate seeing '-0' so I think DJGPP is better here.
Here is the patch for the printf 'g' conversion modification.
File: libc/ansi/stdio/doprnt.c
479a480,481
> int doextradps=0; /* Do extra decimal places if the precision
needs it */
> int doingzero=0; /* We're displaying 0.0 */
526a529,535
> /* If integer is zero then we need to look at where the sig figs are
*/
> if (integer<1) {
> /* If fract is zero the zero before the decimal point is a sig
fig */
> if (fract==0.0) doingzero=1;
> /* If fract is non-zero all sig figs are in fractional part */
> else doextradps=1;
> }
663,665c672,680
< /* a precision of 0 is treated as a precision of 1. */
< if (!prec)
< ++prec;
---
> if (prec) {
> /* If doing zero and precision is greater than 0 count the
> * 0 before the decimal place */
> if (doingzero) --prec;
> }
> else {
> /* a precision of 0 is treated as precision of 1 unless doing
zero */
> if (!doingzero) ++prec;
> }
710c725,731
< prec--;
---
> /* If we're not adding 0s
> * or we are but they're sig figs:
> * decrement the precision */
> if ((doextradps!=1) || ((int)tmp!=0)) {
> doextradps=0;
> prec--;
> }
- Raw text -