[libcxx-commits] [libcxx] [libc++][math] Add `constexpr` to `copysign` functions (PR #216285)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 14 05:38:57 PDT 2026
================
@@ -24,19 +24,33 @@ namespace __math {
// copysign
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
+[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI float
+copysign(float __x, float __y) _NOEXCEPT {
return ::__builtin_copysignf(__x, __y);
}
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT {
+[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI long double
+copysign(long double __x, long double __y) _NOEXCEPT {
return ::__builtin_copysignl(__x, __y);
}
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> copysign(_A1 __x, _A2 __y) _NOEXCEPT {
+[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2>
+copysign(_A1 __x, _A2 __y) _NOEXCEPT {
return ::__builtin_copysign(__x, __y);
}
+#ifdef _LIBCPP_PREFERRED_OVERLOAD
+[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD float copysignf(float __x, float __y) _NOEXCEPT {
+ return __builtin_copysignf(__x, __y);
+}
+[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD long double
+copysignl(long double __x, long double __y) _NOEXCEPT {
+ return __builtin_copysignl(__x, __y);
+}
+#endif
+
----------------
philnik777 wrote:
It won't. GCC doesn't have `__attribute__((enable_if))`. If it did, we wouldn't have to check whether we have it everywhere.
https://github.com/llvm/llvm-project/pull/216285
More information about the libcxx-commits
mailing list