[libcxx-commits] [libcxx] [libc++][math] Add `constexpr` for `std::signbit()` (PR #105946)

Robin Caloudis via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 29 00:51:24 PDT 2024


================
@@ -29,17 +29,64 @@ namespace __math {
 // signbit
 
 template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
+_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
+// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
+#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
+  return __builtin_copysign(1.0, __x) == -1.0;
+#else
   return __builtin_signbit(__x);
+#endif
----------------
robincaloudis wrote:

Thank you. I am not sure how to properly test on CI then. As the constexpr `__builtin_signbit` was just added recently in https://github.com/llvm/llvm-project/pull/94118, the `__builtin_signbit` is not available as `constexpr` in the Clang versions (17,18,19) running on CI. We do not have any bootstrap builds running on CI, do we? 

https://github.com/llvm/llvm-project/pull/105946


More information about the libcxx-commits mailing list