Kingwei 2005.3.11
Experimental environment: DEV-C 4.9.6.0 (GCC / MINGW32), use -wall compile options
#include
Int main () {float v_float; double v_double; long double v_long_double; printf ("SizeOf (Float) =% u / n", sizeof (float)); Printf ("Sizeof (Double) =% u / n", Sizeof (Double); Printf ("lengthof (long double =% u / n", sizeof (long double)); / * -3.40282E 038 ~ 3.40282E 038 * / scanf ("% f", & v_float PRINTF ("% f / n", v_float); Printf ("% E / N", v_float);
/ * -1.79769E 308 ~ 1.79769E 308 * / scanf ("% lf", & v_double); Printf ("% f / n", v_double); printf ("% E / N", v_double); / * -1.79769E 308 ~ 1.79769E 308 * / scanf ("% lf", & v_long_double; printf ("% lf / n", v_long_double); Printf ("% le / n", v_long_double);
Return 0;}
1. Float, Double, Long Double Length is:
Sizeof (float) = 4sizeof (double) = 8sizeof (long double) = 12
2. Numerical range test
Float /- 3.40282E 038DOUBLE /- 1.79769E 308long double /- 1.79769E 308
----- Test Case # 1 forward extreme value -----
3.40282e 0381.79769e 3081.79769e 308
OUTPUT:
340282001837565600000000000000000000000.0000003.402820e 038179769000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000001.797690e 308179769000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000001.797690e 308 ----- Test case # 2 negative extremum -----
-3.40282E 038-1.79769E 308-1.79769E 308
OUTPUT:
-340282001837565600000000000000000000000.000000-3.402820e 038-179769000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000-1.797690e 308-179769000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000-1.797690e 308
----- Test Case # 3 in the forward spill -----
3.40283E 0381.79770E 3081.79770E 308
OUTPUT:
1. # inf001. # Inf00e 0001. # inf001. # Inf00e 0001. # INF001. # inf00e 000
----- Test case # 4 negative overflow ------ 3.40283e 038-1.79770e 308-1.79770e 308
OUTPUT:
-1. # INF00-1. # INF00-1. # INF00-1. # INF00-1. # INF00E 000
It can be seen that although Long Double is 4 bytes longer than Double, but the numerical range indicated is the same. Long Double type length, accuracy and representation range are related to the compiler, operating system, etc. used.
Use the IEEE standard floating point number under VC 6.0, long double is 80-bit length, the range is approximately /- 1.2e 4932, the PrintF format is:% LF,% le,% LG. (Unfounded)
3. Rules of floating point parameters stack: Float (4 bytes) type extends into a Double (8 bytes).
So when entering, you need to distinguish FLOAT (% F) and Double (% LF), while in output, with% f, the Printf function will press the stack of FLOAT (extended into double) according to the Double type rule. Output with Double data. If the% LF format is specified when the output is specified, the GCC compiler will give a warning.
4. The GCC compiler can select the length of FLOAT, whether it is consistent with DOUBLE.