https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114863

            Bug ID: 114863
           Summary: std::format applying grouping to nan's and inf's
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lcarreon at bigpond dot net.au
  Target Milestone: ---

The following code:

#include <locale>
#include <limits>
#include <iostream>
#include <format>

int main()
{
  std::locale::global(std::locale{"en_AU.utf8"});

  double values[] =
  {
    std::numeric_limits<double>::quiet_NaN(),
    -std::numeric_limits<double>::quiet_NaN(),
    std::numeric_limits<double>::signaling_NaN(),
    -std::numeric_limits<double>::signaling_NaN(),
    std::numeric_limits<double>::infinity(),
    -std::numeric_limits<double>::infinity()
  };

  for (const auto& value : values)
  {
    std::cout << std::format("{0:Le}  {0:Lf}  {0:Lg}", value) << std::endl;
  }

  return 0;
}

Generates the following output:

nan  nan  nan
-,nan  -,nan  -,nan
nan  nan  nan
-,nan  -,nan  -,nan
inf  inf  inf
-,inf  -,inf  -,inf

Which in my opinion is incorrect because it applied thousands separator
grouping.  Grouping should only be applied to finite values displayed in fixed
format.

Reply via email to