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

Fix and improve float formatting #1309

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Conversation

fmeum
Copy link
Contributor

@fmeum fmeum commented Nov 21, 2024

12e+34 is no longer broken into 12e + 34.

Also adds a rewrite pass that turns e.g. .23E+021 into 0.23e21:

  • adds a leading 0 to floats
  • removes leading +s and 0s from the exponent
  • lowercases E

build/testdata/003.golden Outdated Show resolved Hide resolved
Copy link
Member

@vladmos vladmos left a comment

Choose a reason for hiding this comment

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

Do I understand it correctly that it allows some invalid expressions like 1e2e3 or 1.2e3.4? Not insisting that it should be fixed here, maybe it's actually better to format the rest than fail.

@fmeum
Copy link
Contributor Author

fmeum commented Jan 6, 2025

I added a rewrite pass that adds a leading 0, removes leading 0s and +s from the exponent and lowercases the E.

@fmeum fmeum changed the title Don't break 12e+34 into 12e + 34 Fix and improve float formatting Jan 6, 2025
@fmeum fmeum requested review from vladmos and laurentlb January 10, 2025 08:19
3.539537889086625e24000,
3539537889086624823140625,
0x123,
0xE45,
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this E also be lowercased?

Copy link
Member

Choose a reason for hiding this comment

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

Or this is invalid and just left as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a float, but a hex number. We could discuss whether hex literals should be canonicalized in some way, but I would prefer to handle that in a separate PR.

@vladmos vladmos merged commit 3a48437 into bazelbuild:main Jan 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants