[lex.fcon]

# 5 Lexical conventions [[lex]](./#lex)

## 5.13 Literals [[lex.literal]](lex.literal#lex.fcon)

### 5.13.4 Floating-point literals [lex.fcon]

[floating-point-literal:](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")  
[*decimal-floating-point-literal*](#nt:decimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")  
[*hexadecimal-floating-point-literal*](#nt:hexadecimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")

[decimal-floating-point-literal:](#nt:decimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")  
[*fractional-constant*](#nt:fractional-constant "5.13.4 Floating-point literals [lex.fcon]") [*exponent-part*](#nt:exponent-part "5.13.4 Floating-point literals [lex.fcon]")opt [*floating-point-suffix*](#nt:floating-point-suffix "5.13.4 Floating-point literals [lex.fcon]")opt  
[*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]") [*exponent-part*](#nt:exponent-part "5.13.4 Floating-point literals [lex.fcon]") [*floating-point-suffix*](#nt:floating-point-suffix "5.13.4 Floating-point literals [lex.fcon]")opt

[hexadecimal-floating-point-literal:](#nt:hexadecimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")  
[*hexadecimal-prefix*](lex.icon#nt:hexadecimal-prefix "5.13.2 Integer literals [lex.icon]") [*hexadecimal-fractional-constant*](#nt:hexadecimal-fractional-constant "5.13.4 Floating-point literals [lex.fcon]") [*binary-exponent-part*](#nt:binary-exponent-part "5.13.4 Floating-point literals [lex.fcon]") [*floating-point-suffix*](#nt:floating-point-suffix "5.13.4 Floating-point literals [lex.fcon]")opt  
[*hexadecimal-prefix*](lex.icon#nt:hexadecimal-prefix "5.13.2 Integer literals [lex.icon]") [*hexadecimal-digit-sequence*](lex.icon#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]") [*binary-exponent-part*](#nt:binary-exponent-part "5.13.4 Floating-point literals [lex.fcon]") [*floating-point-suffix*](#nt:floating-point-suffix "5.13.4 Floating-point literals [lex.fcon]")opt

[fractional-constant:](#nt:fractional-constant "5.13.4 Floating-point literals [lex.fcon]")  
[*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]")opt . [*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]")  
[*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]") .

[hexadecimal-fractional-constant:](#nt:hexadecimal-fractional-constant "5.13.4 Floating-point literals [lex.fcon]")  
[*hexadecimal-digit-sequence*](lex.icon#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]")opt . [*hexadecimal-digit-sequence*](lex.icon#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]")  
[*hexadecimal-digit-sequence*](lex.icon#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]") .

[exponent-part:](#nt:exponent-part "5.13.4 Floating-point literals [lex.fcon]")  
e [*sign*](#nt:sign "5.13.4 Floating-point literals [lex.fcon]")opt [*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]")  
E [*sign*](#nt:sign "5.13.4 Floating-point literals [lex.fcon]")opt [*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]")

[binary-exponent-part:](#nt:binary-exponent-part "5.13.4 Floating-point literals [lex.fcon]")  
p [*sign*](#nt:sign "5.13.4 Floating-point literals [lex.fcon]")opt [*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]")  
P [*sign*](#nt:sign "5.13.4 Floating-point literals [lex.fcon]")opt [*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]")

[sign:](#nt:sign "5.13.4 Floating-point literals [lex.fcon]") one of  
+ -

[digit-sequence:](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]")  
[*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")  
[*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]") 'opt [*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")

[floating-point-suffix:](#nt:floating-point-suffix "5.13.4 Floating-point literals [lex.fcon]") one of  
f l f16 f32 f64 f128 bf16 F L F16 F32 F64 F128 BF16

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lex.tex#L1718)

The type of
a [*floating-point-literal*](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]") ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"), [[basic.extended.fp]](basic.extended.fp "6.9.3 Optional extended floating-point types"))
is determined by
its [*floating-point-suffix*](#nt:floating-point-suffix "5.13.4 Floating-point literals [lex.fcon]") as specified in Table [11](#tab:lex.fcon.type "Table 11: Types of floating-point-literals")[.](#1.sentence-1)

[*Note [1](#note-1)*:

The floating-point suffixesf16, f32, f64, f128, bf16,F16, F32, F64, F128, and BF16 are conditionally-supported[.](#1.sentence-2)

See [[basic.extended.fp]](basic.extended.fp "6.9.3 Optional extended floating-point types")[.](#1.sentence-3)

â *end note*]

Table [11](#tab:lex.fcon.type) — Types of [*floating-point-literal*](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")*s* [[tab:lex.fcon.type]](./tab:lex.fcon.type)  

| [ð](#tab:lex.fcon.type-row-1)<br>**[*floating-point-suffix*](#nt:floating-point-suffix "5.13.4 Floating-point literals [lex.fcon]")** | **type** |
| --- | --- |
| [ð](#tab:lex.fcon.type-row-2)<br>none | double |
| [ð](#tab:lex.fcon.type-row-3)<br>f or F | float |
| [ð](#tab:lex.fcon.type-row-4)<br>l or L | long double |
| [ð](#tab:lex.fcon.type-row-5)<br>f16 or F16 | std​::​float16_t |
| [ð](#tab:lex.fcon.type-row-6)<br>f32 or F32 | std​::​float32_t |
| [ð](#tab:lex.fcon.type-row-7)<br>f64 or F64 | std​::​float64_t |
| [ð](#tab:lex.fcon.type-row-8)<br>f128 or F128 | std​::​float128_t |
| [ð](#tab:lex.fcon.type-row-9)<br>bf16 or BF16 | std​::​bfloat16_t |

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lex.tex#L1752)

The [*significand*](#def:significand "5.13.4 Floating-point literals [lex.fcon]") of a [*floating-point-literal*](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]") is the [*fractional-constant*](#nt:fractional-constant "5.13.4 Floating-point literals [lex.fcon]") or [*digit-sequence*](#nt:digit-sequence "5.13.4 Floating-point literals [lex.fcon]") of a [*decimal-floating-point-literal*](#nt:decimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]") or the [*hexadecimal-fractional-constant*](#nt:hexadecimal-fractional-constant "5.13.4 Floating-point literals [lex.fcon]") or [*hexadecimal-digit-sequence*](lex.icon#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]") of a [*hexadecimal-floating-point-literal*](#nt:hexadecimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")[.](#2.sentence-1)

In the significand,
the sequence of [*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")*s* or [*hexadecimal-digit*](lex.icon#nt:hexadecimal-digit "5.13.2 Integer literals [lex.icon]")*s* and optional period are interpreted as a base N real number s,
where N is 10 for a [*decimal-floating-point-literal*](#nt:decimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]") and
16 for a [*hexadecimal-floating-point-literal*](#nt:hexadecimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")[.](#2.sentence-2)

[*Note [2](#note-2)*:

Any optional separating single quotes are ignored when determining the value[.](#2.sentence-3)

â *end note*]

If an [*exponent-part*](#nt:exponent-part "5.13.4 Floating-point literals [lex.fcon]") or [*binary-exponent-part*](#nt:binary-exponent-part "5.13.4 Floating-point literals [lex.fcon]") is present,
the exponent e of the [*floating-point-literal*](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]") is the result of interpreting
the sequence of an optional [*sign*](#nt:sign "5.13.4 Floating-point literals [lex.fcon]") and the [*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")*s* as a base 10 integer[.](#2.sentence-4)

Otherwise, the exponent e is 0[.](#2.sentence-5)

The scaled value of the literal issÃ10e for a [*decimal-floating-point-literal*](#nt:decimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]") andsÃ2e for a [*hexadecimal-floating-point-literal*](#nt:hexadecimal-floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")[.](#2.sentence-6)

[*Example [1](#example-1)*:

The [*floating-point-literal*](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")*s*49.625 and 0xC.68p+2 have the same value[.](#2.sentence-7)

The [*floating-point-literal*](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]")*s*1.602'176'565e-19 and 1.602176565e-19 have the same value[.](#2.sentence-8)

â *end example*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lex.tex#L1786)

If the scaled value is not in the range of representable
values for its type, the program is ill-formed[.](#3.sentence-1)

Otherwise, the value of a [*floating-point-literal*](#nt:floating-point-literal "5.13.4 Floating-point literals [lex.fcon]") is the scaled value if representable,
else the larger or smaller representable value nearest the scaled value,
chosen in an implementation-defined manner[.](#3.sentence-2)
