On upgrading to Ubuntu 22.04 (amd64), I have noticed that the following code has started to give the result 1.4375 instead of the expected value 1472:
#include <charconv>
#include <iostream>
#include <string_view>
int main()
{
std::string_view src{"1.7P10"};
double value;
auto result = std::from_chars(src.data(), src.data() + src.size(), value, std::chars_format::hex);
std::cout << value << '\n';
}
I get the expected result if I change the P
character in the source to lowercase p
. Both uppercase and lowercase work with std::strtod
.
Is std::from_chars
supposed to fail with uppercase exponent characters, or is this a bug in g++/libstdc++?
Command line used to compile:
g++ -std=c++17 test.cpp
(optimisation level appears to have no effect)
Output of g++ --version
:
g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.