@@ -25,16 +25,15 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
25
25
26
26
The following syntaxes are supported:
27
27
28
- - Integer literals
28
+ - [ Integer literals] ( #integer-literals )
29
29
- ` 12345 ` (decimal)
30
30
- ` 0x1FE ` (hexadecimal)
31
31
- ` 0b1010 ` (binary)
32
- - Real-number literals
32
+ - [ Real-number literals] ( #real-number-literals )
33
33
- ` 123.456 ` (digits on both sides of the ` . ` )
34
34
- ` 123.456e789 ` (optional ` + ` or ` - ` after the ` e ` )
35
35
- ` 0x1.2p123 ` (optional ` + ` or ` - ` after the ` p ` )
36
- - Digit separators (` _ ` ) may be used, with
37
- [ some restrictions] ( #digit-separators )
36
+ - [ Digit separators] ( #digit-separators ) (` _ ` )
38
37
39
38
Note that real-number literals always contain a ` . ` with digits on both sides,
40
39
and integer literals never contain a ` . ` .
@@ -102,19 +101,13 @@ or fixed point real-number types to be expressed directly.
102
101
103
102
### Digit separators
104
103
105
- If digit separators (` _ ` ) are included in literals, they must meet the
106
- respective condition :
104
+ A digit separator (` _ ` ) may occur between any two digits within a literal. For
105
+ example :
107
106
108
- - For decimal integers, the digit separators shall occur every three digits
109
- starting from the right. For example, ` 2_147_483_648 ` .
110
- - For hexadecimal integers, the digit separators shall occur every four digits
111
- starting from the right. For example, ` 0x7FFF_FFFF ` .
112
- - For real-number literals, digit separators can appear in the decimal and
113
- hexadecimal integer portions (prior to the period and after the optional ` e `
114
- or mandatory ` p ` ) as described in the previous bullets. For example,
115
- ` 2_147.483648e12_345 ` or ` 0x1_00CA.FEF00Dp+24 `
116
- - For binary literals, digit separators can appear between any two digits. For
117
- example, ` 0b1_000_101_11 ` .
107
+ - Decimal integers: ` 1_23_456_7890 `
108
+ - Hexadecimal integers: ` 0x7_F_FF_FFFF `
109
+ - Real-number literals: ` 2_147.48_3648e12_345 ` or ` 0x1_00CA.FE_F00Dp+2_4 `
110
+ - Binary literals: ` 0b1_000_101_11 `
118
111
119
112
## Divergence from other languages
120
113
@@ -144,10 +137,15 @@ cases for the goal of not leaving room for a lower level language:
144
137
- [ Real number syntax] ( /proposals/p0143.md#real-number-syntax )
145
138
- [ Disallow ties] ( /proposals/p0866.md )
146
139
- [ Digit separator syntax] ( /proposals/p0143.md#digit-separator-syntax )
140
+ - [ 3-digit decimal groupings] ( /proposals/p1983.md#3-digit-decimal-groupings )
141
+ - [ 2-digit or 4-digit hexadecimal digit groupings] ( /proposals/p1983.md#2-digit-or-4-digit-hexadecimal-digit-groupings )
142
+ - [ Disallow digit separators in fractions] ( /proposals/p1983.md#disallow-digit-separators-in-fractions )
147
143
148
144
## References
149
145
150
146
- Proposal
151
147
[ #143 : Numeric literals] ( https://github.com/carbon-language/carbon-lang/pull/143 )
152
148
- Proposal
153
149
[ #866 : Allow ties in floating literals] ( https://github.com/carbon-language/carbon-lang/pull/866 )
150
+ - Proposal
151
+ [ #1983 : Weaken digit separator placement rules] ( https://github.com/carbon-language/carbon-lang/pull/1983 )
0 commit comments