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

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

Closed
StephanTLavavej opened this issue Nov 17, 2023 · 2 comments · Fixed by #4212
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@StephanTLavavej
Copy link
Member

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 .

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Nov 17, 2023
@MattStephanson
Copy link
Contributor

The STL appears to be sending the correct format flags to printf. The UCRT seems to be adding the point regardless of whether the value is finite or not. Perhaps we could work around it by omitting the # flag for non-finite values.

image

@frederick-vs-ja
Copy link
Contributor

The STL appears to be sending the correct format flags to printf. The UCRT seems to be adding the point regardless of whether the value is finite or not. Perhaps we could work around it by omitting the # flag for non-finite values.

image

Thanks! I've verified that this is essentially a bug of UCRT and reported DevCom-10519861.

I think we should add some workaround at this moment.

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!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants