This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4515. format: a and A should insert the 0x or 0X prefix

Section: 28.5.2.2 [format.string.std] Status: New Submitter: Tianying Chen Opened: 2026-01-30 Last modified: 2026-01-31

Priority: Not Prioritized

View other active issues in [format.string.std].

View all other issues in [format.string.std].

View all issues with New status.

Discussion:

In format, the floating-point presentation types a and A are specified in terms of to_chars in chars_format::hex format. However, to_chars explicitly specifies that there's no leading 0x in the result if fmt is chars_format::hex. This causes inconsistency in the presence of 0x or 0X prefix between format/print and printf/iostream:

std::println("{:a} {:A}", std::numbers::e, -std::numbers::phi);
std::printf("%a %A\n", std::numbers::e, -std::numbers::phi);

may produce

1.5bf0a8b145769p+1 -1.9E3779B97F4A8P+0
0x1.5bf0a8b145769p+1 -0X1.9E3779B97F4A8P+0

We should fix the behavior of a and A in format to include the 0x and 0X prefix respectively.

Victor Zverovich noted that format intended to print hexfloat with 0x like other text formatting facilities, and that an unintentional change of behavior was introduced in P0645R4 when switching to to_chars-based wording.

Proposed resolution:

This wording is relative to N5032.

  1. Modify Table [tab:format.type.float] in 28.5.2.2 [format.string.std] as indicated:

    Table 110 — Meaning of type options for floating-point types [tab:format.type.float]
    Type Meaning
    a If precision is specified, equivalent to
    to_chars(first, last, value, chars_format::hex, precision)
    
    where precision is the specified formatting precision; equivalent to
    to_chars(first, last, value, chars_format::hex)
    
    otherwise. In either case, when value is finite, the base prefix
    0x is inserted after the sign character (possibly space) if there is one,
    or before the output of to_chars otherwise.
    A The same as a, except that it uses uppercase letters for digits above 9 and P to indicate
    the exponent, and that the base prefix is 0X.
    […]