Skip to content

Commit

Permalink
Define overloads as templates
Browse files Browse the repository at this point in the history
  • Loading branch information
robincaloudis committed Sep 11, 2024
1 parent 9c24e8d commit 5527761
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions libcxx/include/__math/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,21 @@ namespace __math {
# define _LIBCPP_SIGNBIT_CONSTEXPR
#endif

// The universal C runtime (UCRT) in the WinSDK provides overloads for all floating point types
// for std::signbit(). We need to work around it as the compilation would otherwise error out
// due to duplicated definitions for clang-cl builds.
#if defined(_LIBCPP_MSVCRT) && defined(_LIBCPP_PREFERRED_OVERLOAD)
# define LIBCPP_SIGNBIT_OVERLOAD _LIBCPP_PREFERRED_OVERLOAD
#else
# define LIBCPP_SIGNBIT_OVERLOAD
#endif

_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI LIBCPP_SIGNBIT_OVERLOAD bool
signbit(float __x) _NOEXCEPT {
// The universal C runtime (UCRT) in the WinSDK provides floating point overloads
// for std::signbit(). By defining our overloads as templates, we can work around
// this issue as templates are less preferred than non-template functions.
template <class T = void>
_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(float __x) _NOEXCEPT {
return __builtin_signbit(__x);
}

_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI LIBCPP_SIGNBIT_OVERLOAD bool
signbit(double __x) _NOEXCEPT {
template <class T = void>
_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(double __x) _NOEXCEPT {
return __builtin_signbit(__x);
}

_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI LIBCPP_SIGNBIT_OVERLOAD bool
signbit(long double __x) _NOEXCEPT {
template <class T = void>
_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(long double __x) _NOEXCEPT {
return __builtin_signbit(__x);
}

Expand Down

0 comments on commit 5527761

Please sign in to comment.