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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://cplusplus.github.io/LWG/issue3081 is relevant too.(In reply to Jan
Schultke from comment #0)
> Consider the following code (https://godbolt.org/z/cjndGqbbT):
> 
> #include <charconv>
> #include <string_view>
> #include <iostream>
> #include <cmath>
> 
> int main() {
>     constexpr char s[] = "-1e-1000";
>     float x;
>     const auto result = std::from_chars(s, std::end(s), x);
>     // x = -1e-1000;
>     std::cout << x;
> }
> 
> libstdc++ prints "0", whereas libc++ and MSVC STL print "-0".
> 
> Also, the handling of negative zero is inconsistent with the spelling of
> floating-point literals. All compilers produce a negative zero for the
> uncommented line, which is actually a negated zero obtained from the
> "1e-1000" floating-point literal with positive value.
> 
> Strictly speaking, I don't think this is a compliance bug because the
> standard doesn't mandate a zero sign for std::from_chars, but I don't think
> this design is intentional. Keep in mind that the string "-0" produces a
> negative zero for libstdc++, meaning that a leading "-" character
> inconsistently affects the sign of the result.

What you're actually seeing here is the uninitialized value of x. it's not
being set to +0.0f it's just not being set at all. You didn't check whether
from_chars actually succeeded.

I think libstdc++ conforms to the standard, but
https://cplusplus.github.io/LWG/issue3081 might be a better approach.

Reply via email to