Skip to content

[charconv.from.chars] Clarify effect of from_chars#6833

Closed
eisenwave wants to merge 1 commit into
cplusplus:mainfrom
eisenwave:charconv-from-chars
Closed

[charconv.from.chars] Clarify effect of from_chars#6833
eisenwave wants to merge 1 commit into
cplusplus:mainfrom
eisenwave:charconv-from-chars

Conversation

@eisenwave

Copy link
Copy Markdown
Member

Fixes #6730.

image

Drafting the wording has revealed an asymmetry with how static_cast works. Say we have a floating-point type T which cannot represent infinity and which can represent [-1, 1] in increments of 0.1.

In that case, static_cast<T>(1.1) is undefined behavior. However, from_chars("1.1") in the current wording is 1.0. My proposed change is editorial only and doesn't change that behavior, but perhaps it should be revisited whether static_cast and from_chars should have matching behavior in this event.

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

but perhaps it should be revisited whether static_cast and from_chars should have matching behavior in this event.

I don't believe they should furtherly match. It doesn't seem intended the character sequence would be parsed as another floating-point type and then converted to the target type.
(Implementations may do so for std::float16_t/std::bfloat16_t by parsing as float, but there won't be such UB in static_cast since std::float16_t and std::bfloat16_t can represent infinities.)

@jwakely

jwakely commented Mar 2, 2024

Copy link
Copy Markdown
Member

I've just added a comment to #6730 saying I'd prefer to handle this via LWG 3082 (maybe with a new proposed resolution) rather than an editorial change.

@tkoeppe

tkoeppe commented Oct 17, 2024

Copy link
Copy Markdown
Contributor

This should be done via an LWG issue.

@tkoeppe tkoeppe closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[charconv.from.chars] Ambiguous specification of floating-point rounding

4 participants