]> gcc.gnu.org Git - gcc.git/commitdiff
libstdc++: Small extended float support tweaks
authorJakub Jelinek <jakub@redhat.com>
Mon, 31 Oct 2022 15:47:23 +0000 (16:47 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 31 Oct 2022 15:49:04 +0000 (16:49 +0100)
The following patch
1) enables the std::float128_t overloads for x86 with glibc 2.26+
2) makes std::nextafter(std::float16_t, std::float16_t) and
   std::nextafter(std::bfloat16_t, std::bfloat16_t) constexpr
3) adds (small) testsuite coverage for that

2022-10-21  Jakub Jelinek  <jakub@redhat.com>

* config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH):
Uncomment.
* include/c_global/cmath (nextafter(_Float16, _Float16)): Make it constexpr.
If std::__is_constant_evaluated() call __builtin_nextafterf16.
(nextafter(__gnu_cxx::__bfloat16_t, __gnu_cxx::__bfloat16_t)): Similarly
but call __builtin_nextafterf16b.
* testsuite/26_numerics/headers/cmath/nextafter_c++23.cc (test): Add
static assertions to test constexpr nextafter.

libstdc++-v3/config/os/gnu-linux/os_defines.h
libstdc++-v3/include/c_global/cmath
libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc

index e5b640a073854f8f1f24d6ef517fda28b14ca8ce..044b4fc91a9ea24aac9f723df20e39c94d6b9fce 100644 (file)
@@ -57,7 +57,7 @@
        || (defined(__powerpc__) && defined(_ARCH_PWR8) \
            && defined(__LITTLE_ENDIAN__) && (_CALL_ELF == 2) \
            && defined(__FLOAT128__)))
-//# define _GLIBCXX_HAVE_FLOAT128_MATH 1
+# define _GLIBCXX_HAVE_FLOAT128_MATH 1
 #endif
 
 #if __GLIBC_PREREQ(2, 27)
index 555d6440849cd7782b597d52c7e4d85225bd3bca..e52055ac474eeacc85b6a0a0d23410c13538acaf 100644 (file)
@@ -2755,9 +2755,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   nearbyint(_Float16 __x)
   { return _Float16(__builtin_nearbyintf(__x)); }
 
-  inline _Float16
+  constexpr _Float16
   nextafter(_Float16 __x, _Float16 __y)
   {
+    if (std::__is_constant_evaluated())
+      return __builtin_nextafterf16(__x, __y);
 #ifdef __INT16_TYPE__
     using __float16_int_type = __INT16_TYPE__;
 #else
@@ -3471,9 +3473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   nearbyint(__gnu_cxx::__bfloat16_t __x)
   { return __gnu_cxx::__bfloat16_t(__builtin_nearbyintf(__x)); }
 
-  inline __gnu_cxx::__bfloat16_t
+  constexpr __gnu_cxx::__bfloat16_t
   nextafter(__gnu_cxx::__bfloat16_t __x, __gnu_cxx::__bfloat16_t __y)
   {
+    if (std::__is_constant_evaluated())
+      return __builtin_nextafterf16b(__x, __y);
 #ifdef __INT16_TYPE__
     using __bfloat16_int_type = __INT16_TYPE__;
 #else
index 45aa3b74b25afc81bd36347168fdc9ef86fedae7..8d7daa9208dd392ed4229055e2ee32a82aafb649 100644 (file)
@@ -100,6 +100,8 @@ test ()
   VERIFY(std::fpclassify(t36) == FP_NAN);
   T t37 = std::nextafter(T(-0.0), T());
   VERIFY(t37 == T() && !std::signbit(t37));
+  static_assert(std::nextafter(T(1.0), T(2.0)) > T(1.0));
+  static_assert(std::nextafter(std::nextafter(T(1.0), T(5.0)), T(0.0)) == T(1.0));
 }
 
 int
This page took 0.065966 seconds and 5 git commands to generate.