Created on 2026-01-30.00:00:00 last changed 1 week ago
Proposed resolution:
This wording is relative to N5032.
Modify Table [tab:format.type.float] in [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 where precision is the specified formatting precision; equivalent toto_chars(first, last, value, chars_format::hex, precision)otherwise. In either case, when value is finite, the base prefixto_chars(first, last, value, chars_format::hex)
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.[…]
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.| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2026-01-31 14:37:05 | admin | set | messages: + msg15915 |
| 2026-01-30 00:00:00 | admin | create | |