Skip to content

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

@zygoloid

Description

@zygoloid

[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lwgIssue must be reviewed by LWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions