This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.

### 3080. Floating point `from_chars` pattern specification breaks round-tripping

Section: 20.19.3 [charconv.from.chars] Status: C++20 Submitter: Greg Falcon Opened: 2018-03-12 Last modified: 2021-02-25

Priority: 0

View other active issues in [charconv.from.chars].

View all other issues in [charconv.from.chars].

View all issues with C++20 status.

Discussion:

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

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

[2018-06 Rapperswil: Adopted]

Proposed resolution:

This wording is relative to N4727.

1. Edit 20.19.3 [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) […]