Skip to content

Commit 528be9e

Browse files
committed
Add floating point overloads for std::signbit
By using `_LIBCPP_PREFERRED_OVERLOAD` we make sure that a given overload is a better match than an otherwise equally good function declaration. Why is there an equally good function declaration in the first place? Underlying the Windows SDK is the UCRT, the universal C runtime, which clang-cl makes use of. The UCRT should provide only C library headers, but does on top comes with overloads for all cv-unqualified floating point types (float, double, long double) for `std::signbit()` in https://github.com/microsoft/win32metadata/blob/e012b29924c53aa941fc010850b68331b0c3ea80/generation/WinSDK/RecompiledIdlHeaders/ucrt/corecrt_math.h#L309-L322. In a certain way, this can be seen as a deviation from the C standard. We need to work around it.
1 parent 7804824 commit 528be9e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

libcxx/include/__math/traits.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,30 @@ namespace __math {
3434
# define _LIBCPP_SIGNBIT_CONSTEXPR
3535
#endif
3636

37-
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
38-
_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
37+
_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
38+
#ifdef _LIBCPP_PREFERRED_OVERLOAD
39+
_LIBCPP_PREFERRED_OVERLOAD
40+
#endif
41+
bool
42+
signbit(float __x) _NOEXCEPT {
43+
return __builtin_signbit(__x);
44+
}
45+
46+
_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
47+
#ifdef _LIBCPP_PREFERRED_OVERLOAD
48+
_LIBCPP_PREFERRED_OVERLOAD
49+
#endif
50+
bool
51+
signbit(double __x) _NOEXCEPT {
52+
return __builtin_signbit(__x);
53+
}
54+
55+
_LIBCPP_NODISCARD inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
56+
#ifdef _LIBCPP_PREFERRED_OVERLOAD
57+
_LIBCPP_PREFERRED_OVERLOAD
58+
#endif
59+
bool
60+
signbit(long double __x) _NOEXCEPT {
3961
return __builtin_signbit(__x);
4062
}
4163

0 commit comments

Comments
 (0)