Skip to content

Difference in hexadecimal floating-point (a) format between fmt and std isn't documented #4657

Description

@statementreply

https://godbolt.org/z/TaK4s5YTM

When formatting floating-point numbers to hexadecimal (a) format, fmt includes the 0x prefix (similar to printf %a), but std doesn't (specified in terms of to_chars). Perhaps std should be fixed.

Activity

  1. soumik15630m commented on Jan 19, 2026

    @soumik15630m
    Contributor
    while (print_xdigits > 0 && xdigits[print_xdigits] == '0') --print_xdigits;
    
      buf.push_back('0');
      buf.push_back(specs.upper() ? 'X' : 'x');
      buf.push_back(xdigits[0]);
    
    

    it's a design choice most probably

  2. vitaut commented on Jan 22, 2026

    @vitaut
    Contributor

    Good catch, thanks! Let me investigate why std::to_chars doesn't print 0x like printf.

  3. soumik15630m commented on Jan 22, 2026

    @soumik15630m
    Contributor

    Happy to help

  4. changed the title [-]Difference in hexadecimal floating-point (`a`) format bewteen `fmt` and `std` isn't documented[/-] [+]Difference in hexadecimal floating-point (`a`) format between `fmt` and `std` isn't documented[/+] on Jan 22, 2026
  5. vitaut commented on Jan 29, 2026

    @vitaut
    Contributor

    I think it's an unintentional change in std::format caused by switching to std::to_chars in one of the revisions of P0645. The reference implementation of std::format always printed 0x like pretty much every other facility and I missed the fact that std::to_chars does something different. The <charconv> paper doesn't mention it so it's unclear why it went with this "innovation". @statementreply, could you by any chance submit an LWG issue?

  6. vitaut commented on Feb 2, 2026

    @vitaut
    Contributor
  7. deleted a comment from Reshi12 on May 14, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions