[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#209136: libc6: printf %#.0g incorrect output



Philip Blundell writes:
 > On Sun, 2003-09-07 at 23:29, Jerry Quinn wrote:
 > > printf("%#.0g", d) gives incorrect results in a couple of cases.
 > > The first case has an extra 0 at the end.  The second case should be a
 > > fixed point output according to the manpage, not scientific output.
 > 
 > Please supply a test program that illustrates this behaviour.  You need
 > to explain exactly what output you see, and what (presumably different)
 > output you feel would be correct.

I thought I had.  I had used the reportbug attach, but apparently the
test got lost.  Here's the test program.  The output I get is:

0.0010
1.e-04

Reading the manpage for printf makes me believe that these are wrong.
Note this is on x86, using gcc 2.95.  Using a recent snapshot of gcc
3.4 gives the same result.


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  union fpstruct {
    double d;
    long x[2];
  } fd;

  fd.x[0]=0x96576b7b; fd.x[1]=0xbf4f519a;
  // This should print 0.001
  printf("%#.0g\n", fd.d);
 
  fd.x[0]=0x674bf7a8; fd.x[1]=0x3f19c5d7;
  printf("%f\n", fd.d);
  // This should print 0.0001, since exp is -04 according to manpage
  printf("%#.0g\n", fd.d);
}



Reply to: