Skip to content

Tracking Issue for float_format_parse_hex #160626

Description

@tgross35

Feature gates: #![feature(float_format_parse_hex)]

This is a tracking issue for formatting and parsing floats in the hex format, e.g. "-0x1.921fb6p+1".

Public API

// 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>;
}

Format details:

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`]+
  • The + formatting flag makes the + always present for nonnegative numbers (same as other number formatting).
  • The 0x is always printed, # makes no difference (unlike integers). 0x is always lowercase.
  • Precision specifiers like {:.4} will zero-pad or truncate the hex digits.
  • The hex sequence and "p" are lowercase for LowerHex, uppercase for UpperHex.
  • If the value is nonzero, the result always starts with 0x1. (0 always prints as 0x0p+0 or -0x0p+0)
  • The . and hex sequence are omitted if there are no digits other than the leading 1.

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • Should subnormal numbers start with a 1 (normalized) or 0 and remain shifted to match the repr?
  • Is it worth having an error type independent of ParseFloatError?
  • Should we have a way to indicate whether or not parsed values are exact? (Alternative method?)
  • Should we allow omitting the 0x/0X indicator when parsing, for some consistency with from_str_radix?
  • This is gated behind no_fp_fmt_parse, does this make sense? The code is significantly smaller than decimal formatting/parsing.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Aug 6, 2026
  2. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  3. changed the title [-]Tracking Issue for `float_format_hex` and `float_from_hex`[/-] [+]Tracking Issue for `float_format_parse_hex`[/+] on Aug 26, 2026
  4. added 2 commits that reference this issue on Sep 18, 2026
  5. added 4 commits that reference this issue on Sep 18, 2026
  6. added a commit that references this issue on Sep 19, 2026
  7. added 2 commits that reference this issue on Sep 19, 2026
  8. added a commit that references this issue on Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions