|
Home > Archive > Unix questions > November 2006 > printf for "double" and "long double"
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
printf for "double" and "long double"
|
|
| paulwvanc@yahoo.ca 2006-11-29, 1:17 pm |
| hi
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),sizeo
f(long double));
8 4 8 12
I guessed "%lld" for "long long", and "%f" for "float".
how about "double" and "long double"?
thanks.
| |
| Keith Thompson 2006-11-29, 7:22 pm |
| paulwvanc@yahoo.ca writes:
> 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),sizeo
f(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_).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
|
|
|
|
|