9.6 KiB
[lex.fcon]
5 Lexical conventions [lex]
5.13 Literals [lex.literal]
5.13.4 Floating-point literals [lex.fcon]
floating-point-literal:
decimal-floating-point-literal
hexadecimal-floating-point-literal
decimal-floating-point-literal:
fractional-constant exponent-partopt floating-point-suffixopt
digit-sequence exponent-part floating-point-suffixopt
hexadecimal-floating-point-literal:
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part floating-point-suffixopt
hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part floating-point-suffixopt
fractional-constant:
digit-sequenceopt . digit-sequence
digit-sequence .
hexadecimal-fractional-constant:
hexadecimal-digit-sequenceopt . hexadecimal-digit-sequence
hexadecimal-digit-sequence .
exponent-part:
e signopt digit-sequence
E signopt digit-sequence
binary-exponent-part:
p signopt digit-sequence
P signopt digit-sequence
sign: one of
digit-sequence:
digit
digit-sequence 'opt digit
floating-point-suffix: one of
f l f16 f32 f64 f128 bf16 F L F16 F32 F64 F128 BF16
The type of a floating-point-literal ([basic.fundamental], [basic.extended.fp]) is determined by its floating-point-suffix as specified in Table 11.
[Note 1:
The floating-point suffixesf16, f32, f64, f128, bf16,F16, F32, F64, F128, and BF16 are conditionally-supported.
â end note]
Table 11 — Types of floating-point-literals [tab:lex.fcon.type]
| ð floating-point-suffix |
type |
|---|---|
| ð none |
double |
| ð f or F |
float |
| ð l or L |
long double |
| ð f16 or F16 |
std::float16_t |
| ð f32 or F32 |
std::float32_t |
| ð f64 or F64 |
std::float64_t |
| ð f128 or F128 |
std::float128_t |
| ð bf16 or BF16 |
std::bfloat16_t |
The significand of a floating-point-literal is the fractional-constant or digit-sequence of a decimal-floating-point-literal or the hexadecimal-fractional-constant or hexadecimal-digit-sequence of a hexadecimal-floating-point-literal.
In the significand, the sequence of digits or hexadecimal-digits and optional period are interpreted as a base N real number s, where N is 10 for a decimal-floating-point-literal and 16 for a hexadecimal-floating-point-literal.
[Note 2:
Any optional separating single quotes are ignored when determining the value.
â end note]
If an exponent-part or binary-exponent-part is present, the exponent e of the floating-point-literal is the result of interpreting the sequence of an optional sign and the digits as a base 10 integer.
Otherwise, the exponent e is 0.
The scaled value of the literal issÃ10e for a decimal-floating-point-literal andsÃ2e for a hexadecimal-floating-point-literal.
[Example 1:
The floating-point-literals49.625 and 0xC.68p+2 have the same value.
The floating-point-literals1.602'176'565e-19 and 1.602176565e-19 have the same value.
â end example]
If the scaled value is not in the range of representable values for its type, the program is ill-formed.
Otherwise, the value of a floating-point-literal is the scaled value if representable, else the larger or smaller representable value nearest the scaled value, chosen in an implementation-defined manner.