Skip to content

[libc++] std::to_chars precision loss for 80-bit long double #56261

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

Closed
alvinhochun opened this issue Jun 28, 2022 · 6 comments
Closed

[libc++] std::to_chars precision loss for 80-bit long double #56261

alvinhochun opened this issue Jun 28, 2022 · 6 comments
Assignees
Labels
confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@alvinhochun
Copy link
Contributor

alvinhochun commented Jun 28, 2022

std::to_char in libc++ converts long double to double:

to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
__first, __last, static_cast<double>(__value), __fmt, __precision);

Test shows libc++ std::to_char output being different from printf/std::ostream, and compared to libstdc++: https://godbolt.org/z/GsYfTTjq7

@EugeneZelenko EugeneZelenko added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. and removed new issue labels Jun 28, 2022
@mordante mordante self-assigned this Jun 28, 2022
@mordante mordante added the confirmed Verified by a second party label Jun 28, 2022
@mordante
Copy link
Member

The original code was provided by Microsoft, on Windows double and long double have the same size.
It's on my todo list to improve this at some point, it's also listed at the status page.

https://libcxx.llvm.org/Status/Cxx17.html#note-p0067

@alvinhochun
Copy link
Contributor Author

Before this gets implemented properly, would it be better to delete the to_chars overload for long double if it has a different size than double? Seems to me that having it produce the wrong result can do more harm than making it unavailable.

@JustAnotherHumanBeing
Copy link

And when will libc++ support from_chars for floating types?

@mordante
Copy link
Member

Before this gets implemented properly, would it be better to delete the to_chars overload for long double if it has a different size than double? Seems to me that having it produce the wrong result can do more harm than making it unavailable.

During review there were no objections and we already shipped this. So we can no longer remove it. There will be differences in some cases, but I'm not sure how often that happens in practice. I'm not even sure whether anybody still uses long doubles.

And when will libc++ support from_chars for floating types?

It's on my todo list, however that list is rather long and this item doesn't have a high priority for me. So I don't expect to work on it this year. Maybe somebody else will pick it up before it's on the top of my list.

@mordante
Copy link
Member

Since we typically don't use the bug tracker for not implemented features I'm closing this.

@WarrenWeckesser
Copy link

A very late "strong agree" with @alvinhochun's comment. That silent cast to double is an annoying "gotcha".

I'm not even sure whether anybody still uses long doubles.

The 80 bit extended precision long doubles aren't that useful. But true IEEE float128 is available on some platforms, and that can be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

5 participants