Bug#209136: libc6: printf %#.0g incorrect output
At Sun, 07 Sep 2003 23:51:40 -0400,
Jerry Quinn wrote:
> 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.
This is not printf bug, but math issue. And your variable is not
appropriate. Please try and report.
> #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;
fd.x[0]=0xd2f1a9fc; fd.x[1]=0x3f50624d;
> // This should print 0.001
> printf("%#.0g\n", fd.d);
>
> fd.x[0]=0x674bf7a8; fd.x[1]=0x3f19c5d7;
fd.x[0]=0xeb1c432d; fd.x[1]=0x3f1a36e2;
> printf("%f\n", fd.d);
> // This should print 0.0001, since exp is -04 according to manpage
> printf("%#.0g\n", fd.d);
> }
Regards,
-- gotom
Reply to: