Title
Floating point from_chars pattern specification breaks round-tripping
Status
c++20
Section
[charconv.from.chars]
Submitter
Greg Falcon

Created on 2018-03-12.00:00:00 last changed 45 months ago

Messages

Date: 2018-06-12.01:05:16

Proposed resolution:

This wording is relative to N4727.

  1. Edit [charconv.from.chars] as indicated:

    from_chars_result from_chars(const char* first, const char* last, float& value,
                                 chars_format fmt = chars_format::general);
    from_chars_result from_chars(const char* first, const char* last, double& value,
                                 chars_format fmt = chars_format::general);
    from_chars_result from_chars(const char* first, const char* last, long double& value,
                                 chars_format fmt = chars_format::general);
    

    -6- Requires: fmt has the value of one of the enumerators of chars_format.

    -7- Effects: The pattern is the expected form of the subject sequence in the "C" locale, as described for strtod, except that

    1. (7.1) — the only sign '+' that may only appear is '-'in the exponent part;

    2. (7.2) […]

    3. (7.3) […]

    4. (7.4) […]

Date: 2018-06-12.01:05:16

[ 2018-06 Rapperswil: Adopted ]

Date: 2018-03-27.00:00:00

[ 2018-03-27 Moved to Tentatively Ready after 9 positive votes on c++std-lib. ]

Date: 2018-03-12.00:00:00

from_chars specifies that the '+' character is never matched, but to_chars specifies its output format in terms of printf(), which puts a '+' sign before positive exponents.

Since strtod() matches '+' signs, it is also desirable to accept '+' in exponents, so that code currently using strtod() can be migrated to from_chars() without a breaking semantic change.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2018-06-12 01:05:16adminsetmessages: + msg9888
2018-06-12 01:05:16adminsetstatus: voting -> wp
2018-05-06 19:23:13adminsetstatus: ready -> voting
2018-03-31 11:58:32adminsetmessages: + msg9791
2018-03-31 11:58:32adminsetstatus: new -> ready
2018-03-24 20:49:28adminsetmessages: + msg9769
2018-03-12 00:00:00admincreate