A real binary floating point constant 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.
Binary floating point literal syntax .-----------. .-------. V | V | >>-+---+-------+-+--.----digit-+--| exponent |-+--+---+-------->< | '-digit-' | +-f-+ | .-------. | +-F-+ | V | | +-l-+ +---digit-+--.--| exponent |----------------+ '-L-' | .-------. | | V | | '---digit-+--| exponent |-------------------' Exponent .-------. V | |--+-e-+--+----+----digit-+-------------------------------------| '-E-' +-+--+ '- --'
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 |
Real hexadecimal floating constants, which are a C99 feature, consist of the following:
The significant part represents a rational number and is composed of the following:
The optional fraction part is a period followed by a sequence of hexadecimal digits.
The exponent part indicates the power of 2 to which the significant part is raised, and is an optionally signed decimal integer. The type suffix is optional. The full syntax is as follows:
Hexadecimal floating point literal syntax >>-+-0x-+-------------------------------------------------------> '-0X-' .------------------. .------------------. V | V | >--+---+--------------+-+--.----+-digit_0_to_f-+-+--| exponent |-+--> | +-digit_0_to_f-+ '-digit_0_to_F-' | | '-digit_0_to_F-' | | .------------------. | | V | | +---+-digit_0_to_f-+-+--.--| exponent |-----------------------+ | '-digit_0_to_F-' | | .------------------. | | V | | '---+-digit_0_to_f-+-+--| exponent |--------------------------' '-digit_0_to_F-' >--+---+------------------------------------------------------->< +-f-+ +-F-+ +-l-+ '-L-' Exponent .--------------. V | |--+-p-+--+----+----digit_0_to_9-+------------------------------| '-P-' +-+--+ '- --'
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. You can omit either the whole-number part or the fraction part, but not both. The binary exponent part is required to avoid the ambiguity of the type suffix F being mistaken for a hexadecimal digit.
Complex literals, which are a C99 feature, are constructed in two parts: the real part, and the imaginary part.
The floating point constant can be specified as a decimal or hexadecimal floating point constant (including optional suffixes), in any of the formats described in the previous sections.Complex literal syntax >>-| real part |--+-------+--| imaginary part |-----------------> '-+-- –-' >--| Imaginary part |--floating point constant--*--_Complex_I-->< Real part |--floating point constant--------------------------------------|
_Complex_I is a macro defined in the complex.h header file, representing the imaginary unit i, the square root of -1.
varComplex = 2.0f + 2.0f * _Complex_I;initializes the complex variable varComplex to a value of 2.0 + 2.0i.
For
ease of porting applications developed with GNU C, XL C/C++ also
allows you to indicate the imaginary part of a complex literal with
a suffix, in addition to the standard suffixes that indicate the type
of the complex number (float, double,
or long double).
>>-| real part |--+-------+--| imaginary part |---------------->< '-+-- –-' real part |----floating point constant------------------------------------| imaginary part |--floating point constant--imaginary-suffix--------------------|
floating point constant can be specified as a decimal or hexadecimal floating point constant (including optional suffixes), in any of the formats described in the previous sections.
imaginary-suffix is one of the suffixes i, I, j, or J, representing the imaginary unit.
varComplex = 3.0f + 4.0fi;initializes the complex variable varComplex to a value of 3.0 + 4.0i.