]> gcc.gnu.org Git - gcc.git/commit
libstdc++: std::from_chars std::{,b}float16_t support
authorJakub Jelinek <jakub@redhat.com>
Tue, 1 Nov 2022 12:41:57 +0000 (13:41 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 1 Nov 2022 12:41:57 +0000 (13:41 +0100)
commit81f98afa22815e7397714caf6fa0fc815803ebaa
tree582a423d7f04db8e004af5371a0026d8c2bc33e1
parent0ae26533b3e26866f4130d40ec0659c273552643
libstdc++: std::from_chars std::{,b}float16_t support

The following patch adds std::from_chars support, similarly to the
previous std::to_chars patch through APIs that use float instead of
the 16-bit floating point formats as container.
The patch uses the fast_float library and doesn't need any changes
to it, like the previous patch it introduces wrapper classes around
float that represent the float holding float16_t or bfloat16_t value,
and specializes binary_format etc. from fast_float for these classes.

The new test verifies exhaustively to_chars and from_chars afterward
results in the original value (except for nans) in all the fmt cases.

2022-11-01  Jakub Jelinek  <jakub@redhat.com>

* include/std/charconv (__from_chars_float16_t,
__from_chars_bfloat16_t): Declare.
(from_chars): Add _Float16 and __gnu_cxx::__bfloat16_t overloads.
* config/abi/pre/gnu.ver (GLIBCXX_3.4.31): Export
_ZSt22__from_chars_float16_tPKcS0_RfSt12chars_format and
_ZSt23__from_chars_bfloat16_tPKcS0_RfSt12chars_format.
* src/c++17/floating_from_chars.cc
(fast_float::floating_type_float16_t,
fast_float::floating_type_bfloat16_t): New classes.
(fast_float::binary_format<floating_type_float16_t>,
fast_float::binary_format<floating_type_bfloat16_t>): New
specializations.
(fast_float::to_float<floating_type_float16_t>,
fast_float::to_float<floating_type_bfloat16_t>,
fast_float::to_extended<floating_type_float16_t>,
fast_float::to_extended<floating_type_bfloat16_t>): Likewise.
(fast_float::from_chars_16): New template function.
(__floating_from_chars_hex): Allow instantiation with
fast_float::floating_type_{,b}float16_t.
(from_chars): Formatting fixes for float/double/long double overloads.
(__from_chars_float16_t, __from_chars_bfloat16_t): New functions.
* testsuite/20_util/to_chars/float16_c++23.cc: New test.
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/include/std/charconv
libstdc++-v3/src/c++17/floating_from_chars.cc
libstdc++-v3/testsuite/20_util/to_chars/float16_c++23.cc [new file with mode: 0644]
This page took 0.048429 seconds and 5 git commands to generate.