From: Andrew Gibson Newsgroups: comp.os.msdos.djgpp Subject: Re: printf 'g' conversion Date: Mon, 02 Mar 1998 12:45:17 +0000 Message-ID: <34FAA9D8.CF1A4A39@petrologic.co.uk> References: NNTP-Posting-Host: petrologic.demon.co.uk MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 7bit Lines: 59 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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--; > }