A “floating-point constant” is a decimal number that represents a signed real number. The representation of a signed real number includes an integer portion, a fractional portion, and an exponent. Use floating-point constants to represent floating-point values that cannot be changed.
floating-point-constant :
fractional-constant exponent-part opt floating-suffix opt
digit-sequence exponent-part floating-suffix opt
fractional-constant :
digit-sequence opt . digit-sequence
digit-sequence .
exponent-part :
e sign opt digit-sequence
E sign opt digit-sequence
sign : one of
+ –
digit-sequence :
digit
digit-sequence digit
floating-suffix : one of
f l F L
You can omit either the digits before the decimal point (the integer portion of the value) or the digits after the decimal point (the fractional portion), but not both. You can leave out the decimal point only if you include an exponent. No white-space characters can separate the digits or characters of the constant.
The following examples illustrate some forms of floating-point constants and expressions:
15.75
1.575E1 /* = 15.75 */
1575e-2 /* = 15.75 */
-2.5e-3 /* = -0.0025 */
25E-4 /* = 0.0025 */
Floating-point constants are positive unless they are preceded by a minus sign (–). In such case, the minus sign is treated as a unary arithmetic negation operator.
Floating-point constants have type float, double, or long. A floating-point constant without an f, F, l, or L suffix has type double. If the letter f or F is the suffix, the constant has type float. If suffixed by the letter l or L, it has type long double. For example:
100L /* Has type long */
100F /* Has type float */
100D /* Has type double */
See “Storage of Basic Types” for information about type double, float, and long.
You can omit the integer portion of the floating-point constant, as shown in the following examples. The number .75 can be expressed in many ways, including the following:
.0075e2
0.075e1
.075e1
75e-2
Microsoft Specific
Limits on the values of floating-point constants are given in the Table 1.2. The header file FLOAT.H that the setup program for Microsoft C/C++ version 7.0 installs in your \C700\INCLUDE directory contains this information.Table 1.2 Limits on Floating-Point Constants
Constant | Meaning | Value |
FLT_DIG DBL_DIG LDBL_DIG | Number of digits, q, such that a floating-point number with q decimal digits can be rounded into a floating-point representation and back without loss of precision. | 6 15 18 | |
FLT_EPSILON DBL_EPSILON LDBL_EPSILON | Smallest positive number x, such that x1.0+x, 1.192092896e-07F 2.2204460492503131e-016 1.0842022172485504434e-019L | ||
FLT_MANT_DIG DBL_MANT_DIG LDBL_MANT_DIG | Number of digits in the radix specified by FLT_RADIX in the floating-point significand. In Microsoft C++, the radix is 2; hence these values specify bits. | 24 53 64 | |
, |
Table 1.2 Limits on Floating-Point Constants (continued)
Constant | Meaning | Value |
FLT_MAX DBL_MAX LDBL_MAX | Maximum representable floating-point number. | 3.402823466e+38F 1.7976931348623158e+30 1.189731495357231765e+4932L |
FLT_MAX_10_EXP DBL_MAX_10_EXP LDBL_MAX_10_EXP | Maximum integer such that 10 raised to that number is a representable floating-point number. | 38 308 4932 |
FLT_MAX_EXP DBL_MAX_EXP LDBL_MAX_EXP | Maximum integer such that FLT_RADIX raised to that number is a representable floating-point number. | 128 1024 16384 |
FLT_MIN DBL_MIN LDBL_MIN | Minimum positive value. | 1.175494351e-38F 2.2250738585072014e-308 3.3621031431120935063e-4932L |
FLT_MIN_10_EXP DBL_MIN_10_EXP LDBL_MIN_10_EXP | Minimum negative integer such that 10 raised to that number is a representable floating-point number. | -37 -307 -4931 |
FLT_MIN_EXP DBL_MIN_EXP LDBL_MIN_EXP | Minimum negative integer such that FLT_RADIX raised to that number is a representable floating-point number. | -125 -1021 -16381 |
FLT_RADIX DBL_RADIX LDBL_RADIX | Radix of exponent representation. | 2 2 2 |
FLT_ROUNDS DBL_ROUNDS LDBL_ROUNDS | Rounding mode for floating-point addition. | 1 (near) 1 (near) 1 (near) |
Note that the information in Table 1.2 may differ in future implementations.¨