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

Make scanner accept floating point literals in hex and binary #9106

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

richcarl
Copy link
Contributor

Similar to hex float literals in C 99, but using Erlang's Base#Literal notation we can easily have binary as well. For example, 2#0.10101p8, or 16#fefe.fefep-16. The letter p (as in C99) stands for powers of 2. The exponent, like the base, is always a decimal number.

These can be useful for code generators and other cases where you want to preserve an exact bit representation of a float.

Also allows explicit base 10 for completeness, as in 10#123.345e9 (with the letter e for exponent as normal - p not allowed, since it would make it very easy to miss whether it is a power of 2 or 10).

Currently missing: documentation. Might also need an EEP.

Based on #9104, which improves pinpointing of errors in numerical literals.

Copy link
Contributor

github-actions bot commented Nov 24, 2024

CT Test Results

    2 files     96 suites   1h 7m 37s ⏱️
2 173 tests 2 125 ✅ 48 💤 0 ❌
2 536 runs  2 486 ✅ 50 💤 0 ❌

Results for commit 28ad2e8.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@richcarl
Copy link
Contributor Author

Rebased on #9104 after squashing.

Copy link
Contributor

@bjorng bjorng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. We do need an EEP for any changes to the language.

@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Nov 27, 2024
@richcarl
Copy link
Contributor Author

I'm seeing now that in Ada, which is where Erlang got its <Base> # <Digits> notation from, they have a slightly different notation for the exponent separator in a based numeral. Instead of p or P as in C99, they use #E. For example, 16#f.ff#E2 rather than 16#f.ffp2. It might be better to keep following the Ada style rather than creating a mix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants