Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underscores in numeric literals #3283

Closed
ghost opened this issue Oct 25, 2023 · 0 comments · Fixed by #3746
Closed

Underscores in numeric literals #3283

ghost opened this issue Oct 25, 2023 · 0 comments · Fixed by #3746
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Oct 25, 2023

Problem

this code does not compile:

fn main() {
    let xs = 1_000;
}
error: Expected a ; separating these two statements
  ┌─ hello/src/main.nr:2:14
  │
2 │     let n = 1_000;
  │              ----
  │

Happy Case

using underscores in numeric literals can make code more readable and help developers better understand and work with large numbers

fn main() {
    // Integer literals with underscores
    let one_million = 1_000_000;
    let ten_million = 10_000_000;
    let one_billion = 1_000_000_000;

    // Floating-point literals with underscores
    let pi_approximation = 3.14_15;
    let avogadros_number = 6.022_140_76e23;

    // Binary literals with underscores
    let binary_value = 0b1101_0101_1010_1101;

    // Hexadecimal literals with underscores
    let hex_value = 0x1A3B_7FFF;
}

Alternatives Considered

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@ghost ghost added the enhancement New feature or request label Oct 25, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 25, 2023
github-merge-queue bot pushed a commit that referenced this issue Dec 9, 2023
# Description

## Problem\*

Resolves #3283 

## Summary\*

This PR adds support for underscores in numeric literals. This is
restricted to not allow multiple underscores in a row and a literal
cannot start or end with an underscore.

## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: kevaundray <kevtheappdev@gmail.com>
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

0 participants