Closed gpeterhoff closed 10 months ago
I will take a look. boost::float80_t
and float128_t
use a different path in from_chars
than 32 and 64 do so at least it's consistently wrong.
Hi Matt, I mean this:
template <typename Type>
void println_float(const Type value)
{
std::array<char, 256>
arr_s{}, arr_b{};
const std::to_chars_result
res_s = std::to_chars(arr_s.data(), arr_s.data()+arr_s.size(), value, std::chars_format::general);
const boost::charconv::to_chars_result
res_b = boost::charconv::to_chars(arr_b.data(), arr_b.data()+arr_b.size(), value, boost::charconv::chars_format::general);
std::cout << "stream " << value << std::endl;
std::cout << "to_chars std/gcc " << std::string_view{arr_s.data(), size_t(res_s.ptr-arr_s.data())} << std::endl;
std::cout << "to_chars boost " << std::string_view{arr_b.data(), size_t(res_b.ptr-arr_b.data())} << std::endl;
std::cout << std::endl;
}
int main()
{
using T = double;
using L = std::numeric_limits<T>;
println_float( L::quiet_NaN());
println_float(-L::quiet_NaN());
println_float( L::signaling_NaN());
println_float(-L::signaling_NaN());
return EXIT_SUCCESS;
}
Results
stream nan
to_chars std/gcc nan
to_chars boost nan
stream -nan
to_chars std/gcc -nan
to_chars boost -nan(ind)
stream nan
to_chars std/gcc nan
to_chars boost nan(snan)
stream -nan
to_chars std/gcc -nan
to_chars boost -nan(snan)
regards Gero
Hi Matt, first the code:
and the results (gcc): from nan_pos: boost:Invalid argument
boost:Invalid argument std:Invalid argument boost:Invalid argument std:Invalid argument boost:Invalid argument std:Invalid argument
from nan_neg: boost:Invalid argument
boost:Invalid argument std:-nan boost:-nan std:-nan boost:-nan std:-nan
from nan: boost:Invalid argument
boost:Invalid argument std:nan boost:nan std:nan boost:nan std:nan
to qnan: boost:nan
boost:nan std:nan boost:nan std:nan boost:nan std:nan
to -qnan: boost:-nan(ind) boost:-nan(ind) std:-nan boost:-nan(ind) std:-nan boost:-nan(ind) std:-nan
to snan: boost:nan(snan) boost:nan(snan) std:nan boost:nan(snan) std:nan boost:nan(snan) std:nan
to -snan: boost:-nan(snan)
boost:-nan(snan) std:-nan boost:-nan(snan) std:-nan boost:-nan(snan) std:-nan
in general: from_chars("+nan") is also not supported by the standard (unfortunately).
string values for nan: These deviate from the standard ("nan"/"-nan"). This is documented https://develop.charconv.cpp.al/#to_chars_to_chars_for_floating_point_types, but boost::charconv is incompatible with it.
from_chars "nan"/"-nan": boost::float128_type and boost::float80_t -> do not work boost::float64_t and boost::float32_t -> work
to_chars: -numeric_limits::quiet_NaN and ±numeric_limits::signaling_NaN -> do not work (see string values) (+)numeric_limits::quiet_NaN -> works
thx Gero