Re: printf and long double

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

 



Gedare Bloom wrote:

> >        printf("%llf %lle\n",c,c);
> 
> I think you want %llg instead of %llf.  g is for double-precision, f
> is for single.

That is incorrect. The difference between %f, %e and %g is the
notation used.

%f uses normal decimal notation, %e uses scientific (exponential)
notation, %g uses either notation depending upon what is appropriate
for the magnitude of the value, specifically: %e for values whose
exponent is greater than the precision or less than -4, %f otherwise.

It is impossible to pass a single-precision "float" to printf() etc
due to C's implicit conversion rules: passing a "float" as an argument
whose type isn't specified by a function prototype results in the
value being converted to "double".

Also, using the "ll" modifier for floating-point conversions ("%llf"
etc) is a GNU extension. The C99 standard specifies the "L" modifier
for "long double" conversions ("%Lf" etc); the "ll" modifier only
applies to integer conversions.

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux