Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<format>: incorrect output for some floating-point values #4319

Closed
cpplearner opened this issue Jan 16, 2024 · 1 comment · Fixed by #4327
Closed

<format>: incorrect output for some floating-point values #4319

cpplearner opened this issue Jan 16, 2024 · 1 comment · Fixed by #4327
Labels
bug Something isn't working fixed Something works now, yay! format C++20/23 format

Comments

@cpplearner
Copy link
Contributor

Describe the bug

Revealed by libc++ test std/utilities/format/format.functions/locale-specific_form.pass.cpp.

When neither precision nor type is specified, a floating-point value should be formatted as if by to_chars(first, last, value) ([format.string.std]). But MSVC STL uses to_chars(first, last, value, chars_format::general).

Command-line test case

D:\test>type test-format-2.cpp
#include <format>
#include <iostream>

int main() {
    std::cout << std::format("{}\n", 12345678.0);
    std::cout << std::format("{:}\n", 12345678.0);
}

D:\test>cl /std:c++20 /EHs /utf-8 test-format-2.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.39.33321 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test-format-2.cpp
Microsoft (R) Incremental Linker Version 14.39.33321.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test-format-2.exe
test-format-2.obj

D:\test>test-format-2
12345678
1.2345678e+07

Expected behavior

The second line should also be 12345678.

STL version

https://github.com/microsoft/STL/commit/3eac329d1f614ecf138d96c22a3b02f87076bc4a
@CaseyCarter CaseyCarter added bug Something isn't working format C++20/23 format labels Jan 17, 2024
@StephanTLavavej
Copy link
Member

Yep, this is definitely a bug - plain shortest is different from chars_format::general. Thanks for analyzing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay! format C++20/23 format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants