This repository was archived by the owner on Apr 28, 2025. It is now read-only.
Add support for printing hex float syntax - #483
Merged
Conversation
Contributor
Author
|
Cc @quaternic, more parsing and printing |
Contributor
Author
|
Looks like indicatif needs a temporary pin #484 |
tgross35
force-pushed
the
hex-print
branch
3 times, most recently
from
January 28, 2025 11:53
216dbf7 to
a543e15
Compare
quaternic
reviewed
Jan 28, 2025
| const fn parse_any(s: &str, bits: u32, sig_bits: u32) -> u128 { | ||
| /// Parse any float from hex to its bitwise representation. | ||
| /// | ||
| /// `nan_repr` is passed rather than constructed so the platform-specific NaN is returned. |
Contributor
There was a problem hiding this comment.
Is it necessary to return specifically fN::NAN? Rather than, say, the quiet NaN with 0 payload.
Contributor
Author
There was a problem hiding this comment.
I had this for bitwise equality at some point, but I since removed that path. I'll clean this up.
Contributor
Author
There was a problem hiding this comment.
Removed. I also moved the new struct to hex_float so it is usable for debug printing within libm.
quaternic
reviewed
Jan 28, 2025
| } else { | ||
| "1." | ||
| }; | ||
| let exp_sign = if exponent >= 0 { "+" } else { "" }; |
Contributor
There was a problem hiding this comment.
To always print the exponent sign, you could use the + format flag (https://doc.rust-lang.org/std/fmt/index.html#sign0)
Contributor
Author
There was a problem hiding this comment.
🤯 I don't think I ever knew about that option, thanks
This isn't very useful for constants since the trait constants are available, but does enable roundtripping via hex float syntax.
tgross35
force-pushed
the
hex-print
branch
3 times, most recently
from
January 29, 2025 00:14
ae636dd to
f6b1122
Compare
tgross35
added a commit
that referenced
this pull request
Apr 18, 2025
Add support for printing hex float syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update the
hf*functions to be able to parse infinities and NANs, then add a wrapper type that formats with the hex float syntax.For now this is only being used in
util, but in a followup I will somehow merge this into the existingHextrait so this is displayed from test output.