Bitwise » Forums » RFC Number grouping (0x1200_0070, 123_456, 10_000.00) proposal
Nicolas Léveillé
22 posts

Developping desktop music applications.

#14985 RFC Number grouping (0x1200_0070, 123_456, 10_000.00) proposal
1 month ago Edited by Nicolas Léveillé on April 18, 2018, 6:24 a.m.

Here is a proposal to allow number groupings in numeric literals.

It allows the optional introduction of a single character (here suggested as _) at any position separating consecutive digits shown in the following examples:

0x1200_0070 == 0x12000070
123_456 == 123456
10_000.40 == 10000.42

Problem being addressed:
- Reducing frequency of mistakes in numbers with repeated strings of similar digits
- Readability of numbers


Numeric constants with lots of repeated numbers happen especially with addresses and 64bit numbers.
Embedded platforms for instance have memory mapped addresses that I've caught myself making mistakes at entry.
Human languages have introduced typographic markings for number groupings: thin spaces, commas and dots.
Number groupings vary also between cultures, some mark the thousandth, some the ten-thousandth.
Programming languages of the C family: C++14 has introduced with the ' has an optional number grouping.


The character _ has been chosen in some documentations (I've seen it used in hardware manuals)


Increased readability, optional


- Implementation cost: small (lexer change only)
- Maintenance cost: small (does not interact with other language features)
- User cost: using the feature is optional, so users who don't like it can ignore it. One character is easy to learn and probably isn't too taxing even if it differs from other languages.
- Opportunity cost: the chosen character is can't be used anymore as a digit

Per Vognsen
43 posts
1 project
#14986 RFC Number grouping (0x1200_0070, 123_456, 10_000.00) proposal
1 month ago Edited by Per Vognsen on April 18, 2018, 7:42 a.m.

Thanks for the detailed proposal. This is simple and worth doing.

By the way, you don't have to make highly formal proposals. Feel free to just raise ideas casually and we can discuss them back and forth. In this case I don't think there's much to discuss; you already covered everything.