Re: printf and long double

Glynn Clements <[email protected]>
Newsgroups gmane.linux.c-programming
Message-ID <[email protected]>
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 <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.