From 29ef50b6bc609130a1550cdfc3997d1e501ffb28 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 1 Nov 2022 13:34:51 +0100 Subject: libstdc++-v3: Some std::*float*_t charconv and i/ostream overloads The following patch adds the easy part of , and changes for extended floats. In particular, for the first one only overloads where the _Float* has the same format as float/double/long double and for the latter two everything but the _GLIBCXX_HAVE_FLOAT128_MATH case. For charconv, I'm not really familiar with it, I'm pretty sure we need new libstdc++.so.6 side implementation of from_chars for {,b}float16_t and for to_chars not really sure but for unspecified precision if it should emit minimum characters that to_chars then can unambiguously parse, I think it is less than in the float case. For float128_t {to,from}_chars I think we even have it on the library side already, just ifdefed for powerpc64le only. For i/o stream operator<>, not sure what is better, if not providing anything at all, or doing what we in the end do if user doesn't override the virtual functions, or use {to,from}_chars under the hood, something else? Besides this, the patch adds some further missed // { dg-options "-std=gnu++2b" } spots, I've also noticed I got the formatting wrong in some testcases by not using spaces around VERIFY conditions and elsewhere by having space before ( for calls. The testsuite coverage is limited, I've added test for from_chars because it was easy to port, but not really sure what to do about to_chars, it has for float/double huge testcases which would be excessive to repeat. And for i/ostream not really sure what exactly is worth testing. 2022-11-01 Jakub Jelinek * include/std/charconv (from_chars, to_chars): Add _Float{32,64,128} overloads for cases where those types match {float,double,long double}. * include/std/istream (basic_istream::operator>>): Add _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads. * include/std/ostream (basic_ostream::operator<<): Add _Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads. * testsuite/20_util/from_chars/8.cc: New test. * testsuite/26_numerics/headers/cmath/nextafter_c++23.cc (test): Formatting fixes. * testsuite/26_numerics/headers/cmath/functions_std_c++23.cc: Add dg-options "-std=gnu++2b". (test_functions, main): Formatting fixes. * testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc: Add dg-options "-std=gnu++2b". --- libstdc++-v3/include/std/ostream | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'libstdc++-v3/include/std/ostream') diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index 674decf73cf..ffffec77f38 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -235,6 +235,51 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return _M_insert(__f); } ///@} +#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) + __attribute__((__always_inline__)) + __ostream_type& + operator<<(_Float16 __f) + { + return _M_insert(static_cast(__f)); + } +#endif + +#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) + __attribute__((__always_inline__)) + __ostream_type& + operator<<(_Float32 __f) + { + return _M_insert(static_cast(__f)); + } +#endif + +#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) + __attribute__((__always_inline__)) + __ostream_type& + operator<<(_Float64 __f) + { + return _M_insert(static_cast(__f)); + } +#endif + +#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) + __attribute__((__always_inline__)) + __ostream_type& + operator<<(_Float128 __f) + { + return _M_insert(static_cast(__f)); + } +#endif + +#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) + __attribute__((__always_inline__)) + __ostream_type& + operator<<(__gnu_cxx::__bfloat16_t __f) + { + return _M_insert(static_cast(__f)); + } +#endif + /** * @brief Pointer arithmetic inserters * @param __p A variable of pointer type. -- cgit v1.2.1