| Issue |
171617
|
| Summary |
[libc++] `std::from_chars` incorrectly rejects `1e10000000000000000`
|
| Labels |
|
| Assignees |
|
| Reporter |
eisenwave
|
```cpp
#include <charconv>
#include <string_view>
#include <limits>
bool is_parsable(std::string_view s) {
float x;
const auto [p, ec] = std::from_chars(s.data(), s.data() + s.size(), x);
return ec == std::errc{};
}
int main() {
static_assert(std::numeric_limits<float>::has_infinity);
return is_parsable("1e10000000000000000");
}
```
This program returns `0` (i.e. `1e10000000000000000` cannot be parsed by `from_chars`), but it is required to return `1`.
https://eel.is/c++draft/charconv.from.chars#1 states that `ec` is set to `errc::result_out_of_range` if the parsed value is not in the range representable by `float`.
https://eel.is/c++draft/basic.fundamental#13 says that the range of representable values includes all positive real numbers if positive infinity is representable by `float`. Therefore, no exponent should be too large, and the result is simply rounded to positive infinity.
See also:
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123078
- https://cplusplus.github.io/LWG/issue3081
- https://cplusplus.github.io/CWG/issues/2723.html
The issue is that while the wording is perfectly clear that `std::from_chars` should accept `1e10000000000000000`, that design has been created entirely through an unrelated change to core wording, and it's not intentional. If LWG 3081 was accepted, the behavior of `from_chars` in libc++ would be correct, but LWG 3081 predates CWG 2723, and so it's no longer fixing any lack of clarity or defect in the wording.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs