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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 28 01:30:38 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
+}
+
+_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
+#ifdef _LIBCPP_PREFERRED_OVERLOAD
+_LIBCPP_PREFERRED_OVERLOAD
+#endif
----------------
philnik777 wrote:

I don't think it's worth the additional complexity to add kind-of support for windows. They'll eventually get around to implementing it, and until that point we can just not provide the `constexpr`ness I think.

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


More information about the libcxx-commits mailing list