-
Notifications
You must be signed in to change notification settings - Fork 102
Add support for printing hex float syntax #483
Conversation
Cc @quaternic, more parsing and printing |
Looks like indicatif needs a temporary pin #484 |
216dbf7
to
a543e15
Compare
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to return specifically fN::NAN
? Rather than, say, the quiet NaN with 0 payload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this for bitwise equality at some point, but I since removed that path. I'll clean this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. I also moved the new struct to hex_float
so it is usable for debug printing within libm
.
crates/libm-test/src/num.rs
Outdated
} else { | ||
"1." | ||
}; | ||
let exp_sign = if exponent >= 0 { "+" } else { "" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To always print the exponent sign, you could use the +
format flag (https://doc.rust-lang.org/std/fmt/index.html#sign0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 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.
ae636dd
to
f6b1122
Compare
Add support for printing hex float syntax
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 existingHex
trait so this is displayed from test output.