Mail Archives: djgpp/1992/08/20/11:03:17
Hi DJ,
     I may have found a bug with %g and #lg formats in GCC (version
1.08).  In short I get funny results if I try to print a number, say
1.00001, specifying the number of significant digits to print.  Here
is a small example which illustrates the problem:
======================================================================
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main(argc,argv)
int argc;
char **argv;
{
  if(argc>1){
    double x=atof(argv[1]);
#ifndef __GNUC__
	char buffer[80];
#endif
    printf("x=%13.5lg %13.5g(float) [%13.5lf %13.5f(float)]\n"
		,x,(float)x,x,(float)x);
#ifndef __GNUC__
	printf("Result of gcvt: %s",gcvt(x,5,buffer));
#endif
  }
exit(0);
}
======================================================================
If I compile and run the code with argument 1.00001, the output line
reads: 
x=      1.00001    1.00001001(float) [      1.00001   1.00001(float)]
In the first two fields, the double contains an extra digit (although
the correct one), while the float contains far too many digits.
Similarly, with argument 1.0001 I get:
x=       1.0001        1.0001(float) [      1.00010       1.00010(float)]
which is correct.   I've compiled the code with Microsoft C6.0 and
the two cases given above yield:
x=            1             1(float) [      1.00001 1.00001(float)]
Result of gcvt: 1.
and
x=       1.0001         1.0001(float) [      1.00010       1.00010(float)]
Result of gcvt: 1.0001
both of which are correct.  (I also compiled the code with gcc on a
SUN and with CC with identical results).  Finally, note that although
gcvt is mentioned in docs/funcs.doc (albeit with caveats) it is
apparently not in any library.
Thanks in advance for looking into this.
David Ronis
- Raw text -