Skip to content

Document that hexfloat 'a'/'A' always emits the 0x prefix#4862

Merged
vitaut merged 1 commit into
fmtlib:mainfrom
ny000815:docs/hexfloat-0x-prefix
Jul 20, 2026
Merged

Document that hexfloat 'a'/'A' always emits the 0x prefix#4862
vitaut merged 1 commit into
fmtlib:mainfrom
ny000815:docs/hexfloat-0x-prefix

Conversation

@ny000815

Copy link
Copy Markdown
Contributor

Problem

The documentation for the a/A (hexfloat) type in doc/syntax.md is inaccurate in two ways:

  1. The example is shown as 1.8p+1, without the 0x prefix.
  2. It states that the # flag "adds a 0x prefix".

Both are wrong. In practice fmt always emits the 0x prefix (matching printf's %a), regardless of #.

Reproduction

#include <fmt/format.h>
#include 
#include 
int main() {
  fmt::print("fmt   : [{:a}]\n", 3.0);
  fmt::print("fmt # : [{:#a}]\n", 3.0);
  fmt::print("fmt   : [{:a}]\n", 2.0);
  fmt::print("fmt # : [{:#a}]\n", 2.0);
  std::printf("std   : [%s]\n", std::format("{:a}", 3.0).c_str());
}

Output:
fmt : [0x1.8p+1]
fmt # : [0x1.8p+1] // 0x present with and without #
fmt : [0x1p+1]
fmt # : [0x1.p+1] // # forces a decimal point, not the prefix
std : [1.8p+1] // std::format omits the prefix

So:

  • The 0x prefix is always emitted, like printf's %a (and unlike std::format).
  • The # flag forces a decimal point, not the prefix.

Fix

Update the a row to use the example 0x1.8p+1, note that the 0x prefix is always emitted, and correct the description of #. The implementation is correct; only the docs are updated to match it.

Fixes #4657

@ny000815
ny000815 requested a review from vitaut as a code owner July 20, 2026 20:50
@vitaut
vitaut merged commit bcaa44d into fmtlib:main Jul 20, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants