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.
format: a and A should insert the 0x or 0X prefixSection: 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.
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.
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 aIf precision is specified, equivalent to whereto_chars(first, last, value, chars_format::hex, precision)precisionis the specified formatting precision; equivalent tootherwise. In either case, whento_chars(first, last, value, chars_format::hex)valueis finite, the base prefix
0xis inserted after the sign character (possibly space) if there is one,
or before the output ofto_charsotherwise.AThe same as a, except that it uses uppercase letters for digits above 9 andPto indicate
the exponent, and that the base prefix is0X.[…]