Reading issue
rust-lang / rust · Issue No. 160626
Feature gates: #![feature(float_format_hex)] and #![feature(float_from_hex)]
This is a tracking issue for formatting and parsing floats in the hex format, e.g. "-0x1.921fb6p+1".
// Feature gate: float_format_hex
impl LowerHex for {f16, f32, f64, f128} { /* ... */ }
impl UpperHex for {f16, f32, f64, f128} { /* ... */ }
// Feature gate: float_from_hex
impl {f16, f32, f64, f128} {
// Accepts anything from the IEEE specification, even if it does not exactly match what we produce
fn from_hex<S: AsRef<[u8]>>(src: &S) -> Result<Self, ParseFloatError>;
}’
IEEE specifies the following:
sign [+ −]
digit [0123456789]
hexDigit [0123456789abcdefABCDEF]
hexExpIndicator [Pp]
hexIndicator "0" [Xx]
hexSignificand ( {hexDigit} * "." {hexDigit}+ | {hexDigit}+ "." | {hexDigit}+ )
decExponent {hexExpIndicator} {sign}? {digit}+
hexSequence {sign}? {hexIndicator} {hexSignificand} {decExponent}
We should parse everything it allows. What we emit is slightly more constrained:
HEX_OUTPUT ->
SIGN? `0x` (`1` | `0`) (`.` HEX_SEQUENCE)? HEX_INDICATOR SIGN DEC_SEQUENCE
SIGN -> `+` | `-`
HEX_EXP_INDICATOR -> `p` | `P`
HEX_SEQUENCE -> [`0`-`9` `a`-`f` `A`-`F`]+
DEC_SEQUENCE -> [`0`-`9`]+
+ formatting flag makes the + always present for nonnegative numbers (same as other number formatting).0x is always printed, # makes no difference (unlike integers). 0x is always lowercase.{:.4} will zero-pad or truncate the hex digits.LowerHex, uppercase for UpperHex.0x1. (0 always prints as 0x0p+0 or -0x0p+0). and hex sequence are omitted if there are no digits other than the leading 1.(Remember to update the S-tracking-* label when checking boxes.)
Relay reads this issue against the repository's contribution signals: the files it is likely to touch, how the maintainers triage work this size, and what the first contribution would exercise.
The full analysis for this issue is still being assembled. Until then, the description above and the thread on GitHub are the most reliable context.