[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
Closed
[charconv.from.chars] Clarify how from_chars treats the sign of zero in floating-point underflow#8595eisenwave wants to merge 1 commit into
eisenwave wants to merge 1 commit into
Conversation
…in floating-point underflow
jensmaurer
reviewed
Dec 10, 2025
| 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, |
Member
There was a problem hiding this comment.
"too small" could mean -1e3000, but we don't mean that.
Please pass this through LWG; this needs exposition to the implementers.
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 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This clarification is meant to prevent bugs like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123078
Consider parsing
"-1e-1000000000000000"withstd::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 thatfloat_round_stylecorresponds to ISO/IEC 60559 rounding modes) (or to C23FLT_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.