https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121404
Bug ID: 121404 Summary: to_chars with hex format produces same output for different long double inputs on powerpc64le Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: cassio.neri at gmail dot com Target Milestone: --- I added this test to trunk (be377ef9ce3eb870ffd18ac02dabe32260dfcb6f): // { dg-do run { target c++14 } } // { dg-require-string-conversions "" } #include <charconv> #include <cstdio> #include <iostream> #include <testsuite_hooks.h> int main() { long double const x1 = 1.0l + 1.0e-17l; long double const x2 = 1.0l + .99999999999999899e-17l; VERIFY(x1 != x2); char str1[80] = {}; auto const [ptr1, ec1] = std::to_chars(str1, str1 + sizeof(str1) - 1, x1, std::chars_format::hex); auto const size1 = ptr1 - str1; VERIFY(ec1 == std::errc{}); char str2[80] = {}; auto const [ptr2, ec2] = std::to_chars(str2, str2 + sizeof(str2) - 1, x2, std::chars_format::hex); auto const size2 = ptr2 - str2; VERIFY(ec2 == std::errc{}); std::printf("%La\n%La\n", x1, x2); std::cerr << str1 << '\n' << str2 << '\n'; VERIFY(size1 != size2 || memcmp(str1, str2, size1) != 0); } Only the last VERIFY failed so that x1 and x2 are different but str1 and str2 are equal strings. Furtheremore, the results should be the same obtained by printf with "a" conversion specifier but without "0x". It turns out that printf produces different strings for x1 and x2. The output is: 0x1.00000000000000b877aa3236a4b8p+0 0x1.00000000000000b877aa3236a48p+0 1.00000000000000b877aa3236a48p+0 1.00000000000000b877aa3236a48p+0 /home/cassio/gcc/src/libstdc++-v3/testsuite/20_util/to_chars/6.cc:28: int main(): Assertion 'size1 != size2 || memcmp(str1, str2, size1) != 0' failed. FAIL: 20_util/to_chars/6.cc -std=gnu++17 execution test FWIW: As I mentioned, in bug 121403, I'm working on to_chars to replace Ryu with Tejú Jaguá. However, for hex format to_chars doesn't use Ryu so replacing it won't help. The problem is elsewhere.