Skip to content

[charconv.from.chars] Clarify how from_chars treats the sign of zero in floating-point underflow#8595

Closed
eisenwave wants to merge 1 commit into
cplusplus:mainfrom
eisenwave:patch-58
Closed

[charconv.from.chars] Clarify how from_chars treats the sign of zero in floating-point underflow#8595
eisenwave wants to merge 1 commit into
cplusplus:mainfrom
eisenwave:patch-58

Conversation

@eisenwave

@eisenwave eisenwave commented Dec 9, 2025

Copy link
Copy Markdown
Member

This clarification is meant to prevent bugs like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123078

Consider parsing "-1e-1000000000000000" with std::from_chars.

From https://eel.is/c++draft/charconv.from.chars#1.sentence-7, it follows that this tiny value is rounded according to round_to_nearest, which is supposed to correspond to the ISO/IEC 605559 rounding mode roundTiesToEven. See also https://cplusplus.github.io/LWG/issue4474 (this is not tentatively ready yet, but so far no one in LWG objected that float_round_style corresponds to ISO/IEC 60559 rounding modes) (or to C23 FLT_ROUNDS).

All ISO/IEC 60559 rounding modes preserve the sign in the case of underflow, so a value too small to be represented should result in negative zero.

@eisenwave eisenwave added the P3-Other Triaged issue not in P1 or P2 label Dec 9, 2025
Comment thread source/text.tex
after rounding according to \tcode{round_to_nearest}\iref{round.style}, and
the member \tcode{ec} is value-initialized.
\begin{note}
If the parsed value is too small to be represented,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"too small" could mean -1e3000, but we don't mean that.

Please pass this through LWG; this needs exposition to the implementers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have LWG3081

@eisenwave

Copy link
Copy Markdown
Member Author

For context, I wrote this PR before I was made aware of LWG3081. I don't think there was ever room in the wording to interpret 1e-1000000 as being rejected by from_chars, nor is LWG3081 proposing that, nor would it be reasonable to propose that because MSVC and Clang already accept it, ... but it would be bad timing to do anything editorially right now.

By the time this PR is unblocked by normative changes, we'll probably have some notes and/or better wording anyway, so it doesn't make sense to keep this open.

@eisenwave eisenwave closed this Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3-Other Triaged issue not in P1 or P2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants