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 based floating point literals #9106

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

Conversation

richcarl
Copy link
Contributor

@richcarl richcarl commented Nov 24, 2024

Similar to based float literals in Ada and hex float literals in C 99, using Erlang's Base#Literal notation (inspired by Ada), for example, 2#0.10101#e8, or 16#fefe.fefe#e-16. The # before the exponent is required. 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.

Currently missing: documentation, io formatting, list_to_float/2 implementation.

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 13m 13s ⏱️
2 173 tests 2 126 ✅ 47 💤 0 ❌
2 536 runs  2 487 ✅ 49 💤 0 ❌

Results for commit 0afd8d0.

♻️ 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.

@bjorng bjorng removed the testing currently being tested, tag is used by OTP internal CI label Jan 7, 2025
@bjorng
Copy link
Contributor

bjorng commented Jan 7, 2025

If you write an EEP soon, I think it is still possible that we could include this improvement in OTP 28.

@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Jan 7, 2025
@richcarl
Copy link
Contributor Author

richcarl commented Jan 7, 2025

If you write an EEP soon, I think it is still possible that we could include this improvement in OTP 28.

I was waiting to hear which form the OTP team favours. The Ada style, or the frankenstyle?

@bjorng
Copy link
Contributor

bjorng commented Jan 7, 2025

I was waiting to hear which form the OTP team favours.

OK. I'll try to find out what the team thinks. I've posted a question in our internal forums.

Personally I think we should go for the Ada style.

@richcarl
Copy link
Contributor Author

richcarl commented Jan 7, 2025

Personally I think we should go for the Ada style.

I agree; the # before the exponent makes it clear that the next letter is never part of the mantissa. The C99 form relies on p not being in the allowed a-f, but with the Ada form, Erlang could just accept any base that it already allows for integers.

@richcarl
Copy link
Contributor Author

richcarl commented Jan 7, 2025

EEP PR: erlang/eep#71

@bjorng
Copy link
Contributor

bjorng commented Jan 7, 2025

I've got two comments so far; both prefer the Ada style.

@richcarl
Copy link
Contributor Author

richcarl commented Jan 7, 2025

I've got two comments so far; both prefer the Ada style.

Good; that's what I put in the EEP draft. Just need to update the code to match.

@richcarl richcarl changed the title Make scanner accept floating point literals in hex and binary Make scanner accept based floating point literals Jan 9, 2025
@richcarl
Copy link
Contributor Author

richcarl commented Jan 9, 2025

The code now uses Ada style, i.e. 16#ff.fe#e+6.

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