#include <stdio.h>
#include <float.h>
int main()
{
float num1 = FLT_MAX;
double num2 = DBL_MIN;
long double num3 = LDBL_MAX;
printf("%.2f\n", num1);
printf("%e\n", num2);
printf("%Le\n", num3);
return 0;
}
I am working on exponential notation with C and I don't know why the output of long double is not correct (float and double has an output of
340282346638528859811704183484516925440.00
2.225074e-308
but long double has
1.189731e+4932 (in the book it says 1.797693e+308)
Is the output differ from every computer? Then why my mac has the only different value of the long double but not float and double?
</div>
转载于:https://stackoverflow.com/questions/53038728/c-lang-exponential-long-double-output-mac-os-xcode
As a general statement, the length of each data type is compiler and machine dependent. So the value of float, double and long double are machine and compiler dependent and may be different on different computers
The size of each datatype depends on your compiler and machine, as Sandeep mentioned. float
and double
are almost always IEEE float and double types, but the size of long double
varies from machine to machine.
The three most common sizes for long double are 80 bits (which seems to be what your book is using), 64 bits (same as double), or 128 bits (which seems to be what your computer is using).
You do not have a good C book if it gave you an exact size for your datatypes.
try: printf("sizeof(long double): %d\n", sizeof(long double));
to see what size it is on your machine.