float
Type
This page was translated by a robot.
The type floatstores a real number , which is encoded as a floating point number with 4 bytes. A floatcan represent the value range of 1.175494e-38up 3.402823e+38to 6 decimal places, both positive and negative.
Details
The type floatis a 32-bit floating point number with a 23-bit mantissa. This corresponds to the single precision floating point type in the IEEE 754 standard. Some macros are defined in the floatslibrary , which more precisely specify the value range of floating-point types. The following program supplies the values for the type floaton the author's system:
1.175494e-38
3.402823e+38
24
6
-125
-37
128
38
1.192093e-07
Note that the mantissa number in the floatslibrary always adds an implicit bit. For more detailed information on what this bit is all about and how a floating point number is packed in 32 bits, see floating point coding ..
When specifying fixed values in the source code, floatvalues can be appended with a small for a large Fsuffix. Both suffixes mean the same thing, but the lowercase variant is usually used. Without this suffix, the compiler assumes it is a doublevalue ..
Arithmetic Conversion
In the case of assignments, initializations or casts to a floattype, the compiler may perform arithmetic conversions . The conversion rules for the floattype are described below. In some cases, a compiler issues a warning for unsafe conversions, which can be suppressed if necessary using an explicit cast .
Arithmetic conversions of floating-point values should be avoided whenever possible, regardless of whether they are implicitly or explicitly cast. They are still very expensive even in modern processors. It should also be noted that in certain situations floating point values are automatically doubleconverted into a (see Promotion ).
When converting an integer type to an , an floatattempt is made to represent the number exactly whenever possible. However, since a floatcan only display 6 exact decimal places, only integer values up to and including 7 decimal digits can be saved with guaranteed accuracy.
When a doubleor is converted long doubleto a , an floatattempt is also made to represent the number as accurately as possible. If the floating point number to be converted has no place in a float, then the maximum or minimum possible value is assumed:+-infinity