Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Eisenwave
Copy link
Contributor

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
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
Copy link
Member

jwakely commented Mar 2, 2024

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.

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
3 participants