[Bug libfortran/48651] DTOA float conversion issue

kargl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Apr 17 23:39:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48651

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #5 from kargl at gcc dot gnu.org 2011-04-17 23:38:48 UTC ---
(In reply to comment #3)
> (In reply to comment #2)
> > hmm, notice the typo! i have set ldnum to 0.0 but it still is printing the
> > value of dnum. What am I doing wrong.
> > 
> > $ cat sprint.c 
> > #include <stdio.h>
> > 
> > int
> > main ()
> > {
> >   float num = 0.9;
> >   double dnum = 0.9;
> >   long double ldnum = 25.6;
> >   printf("%50.48f\n", num);
> >   printf("%50.48lf, %d\n", num, sizeof(num));
> >   printf("%80.78f\n", dnum);
> >   printf("%80.78lf, %d\n", dnum, sizeof(dnum));
> >   printf("%80.78f\n", ldnum);
> >   printf("%80.78lf, %d\n", ldnum, sizeof(ldnum));
> 
> Check your format strings, use "lf" only for long double.

man 3 printf

         Modifier    a, A, e, E, f, F, g, G
         l (ell)     double (ignored, same behavior as without it)
         L           long double

L is for long double.  f and lf are essentially identical for double.



More information about the Gcc-bugs mailing list