Skip to content

Number literal syntax - allow underscores or other way to make number more readable #26845

Closed
@rakudrama

Description

@rakudrama

This is likely a 2.x feature.

I would like to be able to use underscores inside number literals to break up long runs of digits.
For example 1000000000 is harder to understand than 1_000_000_000.

Today I saw x & 0x3FFFFFF with a comment saying the result fits in 30 bits.
If you count the Fs, you will see there is an error, but the error has gone unnoticed for several years.
If underscores were permitted, the following difference might be more apparent to the developer or reviewer:

x & 0x_3FF_FFFF     vs     x & 0x_3FFF_FFFF

I would want the exact placement of underscores not be prescribed, the same literal might warrant different structure depending on context. In some byte-oriented code 0x3F_FF_FF_FF might make more sense.

This feature would also make binary literals (0b_1111_1111 = 255) more useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-duplicateClosed in favor of an existing reporttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions