cplusplus / draft

C++ standards drafts
http://www.open-std.org/jtc1/sc22/wg21/
5.65k stars 744 forks source link

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

Open zygoloid opened 9 months ago

zygoloid commented 9 months ago

[charconv.from.chars]/6.4 says:

In any case, the resulting value is one of at most two floating-point values closest to the value of the string matching the pattern.

This is ambiguous. It could mean either:

1) The resulting value is the implementation's choice of one of a set of values, and that set contains the two values closest to the value of the string.

2) The resulting value is the implementation's choice of one of a set of values, and that set contains all values that are closest to the value of the string (of which it turns out there can be up to two).

I think the normal English interpretation would be (1), but the intended interpretation is actually (2).

(Under (1), the string "1.0" can produce the value one ULP less than 1.0 or it can produce 1.0, and the string "1.00<lots of 0s>1" can produce those same two values, because the value one ULP less than 1.0 is closer to that string than the value one ULP greater than 1.0.)

Perhaps the wording from [conv.double]/2 and [expr.static.cast]/11 can be used instead:

If the source value can be exactly represented in the destination type, the result of the conversion is that exact representation. If the source value is between two adjacent destination values, the result of the conversion is an implementation-defined choice of either of those values.

jwakely commented 6 months ago

This conflicts with the proposed resolution of LWG 3082.

jwakely commented 6 months ago

Since we have an open issue, I think I'd prefer to handle it in LWG. Richard's comments can be added to the issue.