Floating-Point Literals

A floating-point literal consists of the following:

Both the integral and fractional parts are made up of decimal digits. You can omit either the integral part or the fractional part, but not both. You can omit either the decimal point or the exponent part, but not both.

     .-----------.     .-------.
     V           |     V       |
>>-+---+-------+-+--.----digit-+--+--------------+-+--+---+----><
   |   '-digit-'                  '-| exponent |-' |  +-f-+
   | .-------.                                     |  +-F-+
   | V       |                                     |  +-l-+
   +---digit-+--.--+--------------+----------------+  '-L-'
   |               '-| exponent |-'                |
   | .-------.                                     |
   | V       |                                     |
   '---digit-+--| exponent |-----------------------'
 
Exponent:
 
                  .-------.
                  V       |
|--+-e-+--+----+----digit-+-------------------------------------|
   '-E-'  +-+--+
          '- --'
 
 

The magnitude range of float is approximately 1.2e-38 to 3.4e38. The magnitude range of double or long double is approximately 2.2e-308 to 1.8e308. If a floating-point constant is too large or too small, the result is undefined by the language.

The suffix f or F indicates a type of float, and the suffix l or L indicates a type of long double. If a suffix is not specified, the floating-point constant has a type double.

A plus (+) or minus (-) symbol can precede a floating-point literal. However, it is not part of the literal; it is interpreted as a unary operator.

The following are examples of floating-point literals:

Floating-Point Constant Value
5.3876e4 53,876
4e-11 0.00000000004
1e+5 100000
7.321E-3 0.007321
3.2E+4 32000
0.5e-6 0.0000005
0.45 0.45
6.e10 60000000000

C When you use the printf function to display a floating-point constant value, make certain that the printf conversion code modifiers that you specify are large enough for the floating-point constant value.

Related References

IBM Copyright 2003