10.05.2011

printf for "double" and "long double" - Unix

printf for "double" and "long double" - Unix:


how to reliably print for "double" and "long double"?
> I've been reading "man 3 printf", but I can't figure it out for
> "double" and "long double".
> here is my system's sizeof's:
> printf("%d %d %d %d\n",sizeof(long
> long),sizeof(float),sizeof(double),sizeof(long double));
> 8 4 8 12
> I guessed "%lld" for "long long", and "%f" for "float".
> how about "double" and "long double"?

This is really a C question rather than a Unix question. If you
have more questions, try comp.lang.c.

Use "%f" for both float and double; a float argument to a variadic
function like printf is automatically promoted to double.

Use "%Lf" for long double.

Or replace the 'f' with 'g' or 'e' to control how the number is
formatted; you can also control the precision.

If this isn't explained clearly in your printf man page (it should
be), try any decent C textbook. K&R2 (Kernighan & Ritchie, _The C
Programming Language_, 2nd edition) is excellent, as is H&S5 (Harbison
& Steele, _C: A Reference Manual_).




We must do something. This is something. Therefore, we must do this.





I COLLECTED IT FOR SELECTING WANTED THINGS HERE...

No comments: