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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 29 03:10:50 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
----------------
philnik777 wrote:

We have a bootstrapping build in the CI, but we should also just update the compilers to be 18, 19, 20, since that's what we actually support now. Would you mind doing that as a separate PR? (It's OK to say no!)

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


More information about the libcxx-commits mailing list