Skip to content

<format>: Hex float precision is capped #2156

@vasama

Description

@vasama

Describe the bug
std::format has a hard limit on the precision of hexadecimal floating point output.

Command-line test case

C:\Users\Untelo\sandbox
λ  cat test.cpp
#include <format>
#include <cassert>
using namespace std;
int main()
{
        char buffer[2048];
        auto r = to_chars(buffer, buffer + sizeof(buffer), 1.0f, chars_format::hex, 2000);
        assert(r.ec == errc{});
        assert( string_view(buffer, r.ptr - buffer) == format("{:.2000a}", 1.0f) );
}
​C:\Users\Untelo\sandbox
λ  cl /EHsc /W4 /WX /std:c++latest test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30133 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

test.cpp
Microsoft (R) Incremental Linker Version 14.29.30133.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
​C:\Users\Untelo\sandbox
λ  ./test
Assertion failed: string_view(buffer, r.ptr - buffer) == format("{:.2000a}", 1.0f), file test.cpp, line 9

Expected behavior
http://eel.is/c++draft/format.string.std#22

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.

STL version
Version 16.11.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!formatC++20/23 format

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions