[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
+}
+
+_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
+#ifdef _LIBCPP_PREFERRED_OVERLOAD
+_LIBCPP_PREFERRED_OVERLOAD
+#endif
----------------
philnik777 wrote:
Ah. Please do that in a separate PR. I didn't realize you change two separate things here.
https://github.com/llvm/llvm-project/pull/105946
More information about the libcxx-commits
mailing list