Skip to content

<ostream>: With setprecision(0) showpoint fixed, a bogus '.' is emitted for infinity and NaN #4210

@StephanTLavavej

Description

@StephanTLavavej
C:\Temp>type meow.cpp
#include <iomanip>
#include <iostream>
#include <limits>
using namespace std;

int main() {
    constexpr double inf_dbl = numeric_limits<double>::infinity();
    constexpr double nan_dbl = numeric_limits<double>::quiet_NaN();

    cout << "setprecision(0) showpoint fixed:\n";
    cout << setprecision(0) << showpoint << fixed;

    cout << inf_dbl << "\n";
    cout << -inf_dbl << "\n";
    cout << nan_dbl << "\n";
    cout << -nan_dbl << "\n";

    cout << "\nAnd showpos:\n";
    cout << showpos;

    cout << inf_dbl << "\n";
    cout << -inf_dbl << "\n";
    cout << nan_dbl << "\n";
    cout << -nan_dbl << "\n";
}
C:\Temp>cl /EHsc /nologo /W4 /MTd /Od meow.cpp && meow
meow.cpp
setprecision(0) showpoint fixed:
i.nf
-.inf
n.an
-.nan(ind)

And showpos:
+i.nf
-.inf
+n.an
-.nan(ind)

libstdc++ and libc++ behave correctly (note that MSVC's STL has an intentional behavior difference regarding negative NaNs, though): https://godbolt.org/z/MYsPxc98h

Originally reported as DevCom-10512845 / VSO-1917556 / AB#1917556 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    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