Skip to content

Fix and improve float formatting#1309

Merged
vladmos merged 4 commits intobazelbuild:mainfrom
fmeum:signed-exponent
Jan 14, 2025
Merged

Fix and improve float formatting#1309
vladmos merged 4 commits intobazelbuild:mainfrom
fmeum:signed-exponent

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

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 laurentlb and vladmos 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
1 check 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