Skip to content

Commit ea0eca5

Browse files
committed
Use signcopy workaround
If constexpr signbit is not available, we make use of signcopy(), which has been constexpr for quite a while in Clang.
1 parent 93bd32b commit ea0eca5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

libcxx/include/__math/traits.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,39 @@ namespace __math {
3030

3131
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
3232
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
33+
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
34+
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
35+
return __builtin_copysign(1.0, __x) == -1.0;
36+
#else
3337
return __builtin_signbit(__x);
38+
#endif
3439
}
3540

3641
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(float __x) _NOEXCEPT {
42+
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
43+
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
44+
return __builtin_copysign(1.0, __x) == -1.0;
45+
#else
3746
return __builtin_signbit(__x);
47+
#endif
3848
}
3949

4050
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(double __x) _NOEXCEPT {
51+
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
52+
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
53+
return __builtin_copysign(1.0, __x) == -1.0;
54+
#else
4155
return __builtin_signbit(__x);
56+
#endif
4257
}
4358

4459
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(long double __x) _NOEXCEPT {
60+
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
61+
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
62+
return __builtin_copysign(1.0, __x) == -1.0;
63+
#else
4564
return __builtin_signbit(__x);
65+
#endif
4666
}
4767

4868
template <class _A1, __enable_if_t<is_integral<_A1>::value && is_signed<_A1>::value, int> = 0>

0 commit comments

Comments
 (0)