Skip to content

Commit 9572a33

Browse files
authored
Update digit separator notes in design (#2117)
1 parent 48ba8bf commit 9572a33

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

docs/design/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ Integers may be written in decimal, hexadecimal, or binary:
285285
- `0x1FE` (hexadecimal)
286286
- `0b1010` (binary)
287287

288-
Underscores `_` may be used as digit separators, but for decimal and hexadecimal
289-
literals, they can only appear in conventional locations. Numeric literals are
288+
Underscores (`_`) may be used as digit separators. Numeric literals are
290289
case-sensitive: `0x`, `0b` must be lowercase, whereas hexadecimal digits must be
291290
uppercase. Integer literals never contain a `.`.
292291

@@ -304,6 +303,8 @@ represent that value.
304303
> [#144: Numeric literal semantics](https://github.com/carbon-language/carbon-lang/pull/144)
305304
> - Proposal
306305
> [#820: Implicit conversions](https://github.com/carbon-language/carbon-lang/pull/820)
306+
> - Proposal
307+
> [#1983: Weaken digit separator placement rules](https://github.com/carbon-language/carbon-lang/pull/1983)
307308
308309
### Floating-point types
309310

@@ -331,6 +332,7 @@ literals are supported:
331332
- `123.456e789` (optional `+` or `-` after the `e`)
332333
- `0x1.Ap123` (optional `+` or `-` after the `p`)
333334

335+
As with integer literals, underscores (`_`) may be used as digit separators.
334336
Real-number literals always have a period (`.`) and a digit on each side of the
335337
period. When a real-number literal is interpreted as a value of a floating-point
336338
type, its value is the representable real number closest to the value of the
@@ -348,6 +350,8 @@ selected.
348350
> [#820: Implicit conversions](https://github.com/carbon-language/carbon-lang/pull/820)
349351
> - Proposal
350352
> [#866: Allow ties in floating literals](https://github.com/carbon-language/carbon-lang/pull/866)
353+
> - Proposal
354+
> [#1983: Weaken digit separator placement rules](https://github.com/carbon-language/carbon-lang/pull/1983)
351355
352356
### String types
353357

docs/design/lexical_conventions/numeric_literals.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2525

2626
The following syntaxes are supported:
2727

28-
- Integer literals
28+
- [Integer literals](#integer-literals)
2929
- `12345` (decimal)
3030
- `0x1FE` (hexadecimal)
3131
- `0b1010` (binary)
32-
- Real-number literals
32+
- [Real-number literals](#real-number-literals)
3333
- `123.456` (digits on both sides of the `.`)
3434
- `123.456e789` (optional `+` or `-` after the `e`)
3535
- `0x1.2p123` (optional `+` or `-` after the `p`)
36-
- Digit separators (`_`) may be used, with
37-
[some restrictions](#digit-separators)
36+
- [Digit separators](#digit-separators) (`_`)
3837

3938
Note that real-number literals always contain a `.` with digits on both sides,
4039
and integer literals never contain a `.`.
@@ -102,19 +101,13 @@ or fixed point real-number types to be expressed directly.
102101

103102
### Digit separators
104103

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:
107106

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`
118111

119112
## Divergence from other languages
120113

@@ -144,10 +137,15 @@ cases for the goal of not leaving room for a lower level language:
144137
- [Real number syntax](/proposals/p0143.md#real-number-syntax)
145138
- [Disallow ties](/proposals/p0866.md)
146139
- [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)
147143

148144
## References
149145

150146
- Proposal
151147
[#143: Numeric literals](https://github.com/carbon-language/carbon-lang/pull/143)
152148
- Proposal
153149
[#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

Comments
 (0)