1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___MATH_TRAITS_H
10 #define _LIBCPP___MATH_TRAITS_H
13 #include <__type_traits/enable_if.h>
14 #include <__type_traits/is_arithmetic.h>
15 #include <__type_traits/is_floating_point.h>
16 #include <__type_traits/is_integral.h>
17 #include <__type_traits/is_signed.h>
18 #include <__type_traits/promote.h>
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 # pragma GCC system_header
25 _LIBCPP_BEGIN_NAMESPACE_STD
31 template <class _A1
, __enable_if_t
<is_floating_point
<_A1
>::value
, int> = 0>
32 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool signbit(_A1 __x
) _NOEXCEPT
{
33 return __builtin_signbit(__x
);
36 template <class _A1
, __enable_if_t
<is_integral
<_A1
>::value
&& is_signed
<_A1
>::value
, int> = 0>
37 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool signbit(_A1 __x
) _NOEXCEPT
{
41 template <class _A1
, __enable_if_t
<is_integral
<_A1
>::value
&& !is_signed
<_A1
>::value
, int> = 0>
42 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool signbit(_A1
) _NOEXCEPT
{
48 template <class _A1
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& numeric_limits
<_A1
>::has_infinity
, int> = 0>
49 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isfinite(_A1 __x
) _NOEXCEPT
{
50 return __builtin_isfinite((typename __promote
<_A1
>::type
)__x
);
53 template <class _A1
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& !numeric_limits
<_A1
>::has_infinity
, int> = 0>
54 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isfinite(_A1
) _NOEXCEPT
{
60 template <class _A1
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& numeric_limits
<_A1
>::has_infinity
, int> = 0>
61 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isinf(_A1 __x
) _NOEXCEPT
{
62 return __builtin_isinf((typename __promote
<_A1
>::type
)__x
);
65 template <class _A1
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& !numeric_limits
<_A1
>::has_infinity
, int> = 0>
66 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isinf(_A1
) _NOEXCEPT
{
70 #ifdef _LIBCPP_PREFERRED_OVERLOAD
71 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isinf(float __x
) _NOEXCEPT
{
72 return __builtin_isinf(__x
);
75 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD
bool
76 isinf(double __x
) _NOEXCEPT
{
77 return __builtin_isinf(__x
);
80 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isinf(long double __x
) _NOEXCEPT
{
81 return __builtin_isinf(__x
);
87 template <class _A1
, __enable_if_t
<is_floating_point
<_A1
>::value
, int> = 0>
88 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isnan(_A1 __x
) _NOEXCEPT
{
89 return __builtin_isnan(__x
);
92 template <class _A1
, __enable_if_t
<is_integral
<_A1
>::value
, int> = 0>
93 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isnan(_A1
) _NOEXCEPT
{
97 #ifdef _LIBCPP_PREFERRED_OVERLOAD
98 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isnan(float __x
) _NOEXCEPT
{
99 return __builtin_isnan(__x
);
102 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD
bool
103 isnan(double __x
) _NOEXCEPT
{
104 return __builtin_isnan(__x
);
107 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isnan(long double __x
) _NOEXCEPT
{
108 return __builtin_isnan(__x
);
114 template <class _A1
, __enable_if_t
<is_floating_point
<_A1
>::value
, int> = 0>
115 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isnormal(_A1 __x
) _NOEXCEPT
{
116 return __builtin_isnormal(__x
);
119 template <class _A1
, __enable_if_t
<is_integral
<_A1
>::value
, int> = 0>
120 _LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
bool isnormal(_A1 __x
) _NOEXCEPT
{
126 template <class _A1
, class _A2
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& is_arithmetic
<_A2
>::value
, int> = 0>
127 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool isgreater(_A1 __x
, _A2 __y
) _NOEXCEPT
{
128 using type
= typename __promote
<_A1
, _A2
>::type
;
129 return __builtin_isgreater((type
)__x
, (type
)__y
);
134 template <class _A1
, class _A2
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& is_arithmetic
<_A2
>::value
, int> = 0>
135 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool isgreaterequal(_A1 __x
, _A2 __y
) _NOEXCEPT
{
136 using type
= typename __promote
<_A1
, _A2
>::type
;
137 return __builtin_isgreaterequal((type
)__x
, (type
)__y
);
142 template <class _A1
, class _A2
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& is_arithmetic
<_A2
>::value
, int> = 0>
143 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool isless(_A1 __x
, _A2 __y
) _NOEXCEPT
{
144 using type
= typename __promote
<_A1
, _A2
>::type
;
145 return __builtin_isless((type
)__x
, (type
)__y
);
150 template <class _A1
, class _A2
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& is_arithmetic
<_A2
>::value
, int> = 0>
151 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool islessequal(_A1 __x
, _A2 __y
) _NOEXCEPT
{
152 using type
= typename __promote
<_A1
, _A2
>::type
;
153 return __builtin_islessequal((type
)__x
, (type
)__y
);
158 template <class _A1
, class _A2
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& is_arithmetic
<_A2
>::value
, int> = 0>
159 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool islessgreater(_A1 __x
, _A2 __y
) _NOEXCEPT
{
160 using type
= typename __promote
<_A1
, _A2
>::type
;
161 return __builtin_islessgreater((type
)__x
, (type
)__y
);
166 template <class _A1
, class _A2
, __enable_if_t
<is_arithmetic
<_A1
>::value
&& is_arithmetic
<_A2
>::value
, int> = 0>
167 _LIBCPP_NODISCARD_EXT
inline _LIBCPP_HIDE_FROM_ABI
bool isunordered(_A1 __x
, _A2 __y
) _NOEXCEPT
{
168 using type
= typename __promote
<_A1
, _A2
>::type
;
169 return __builtin_isunordered((type
)__x
, (type
)__y
);
172 } // namespace __math
174 _LIBCPP_END_NAMESPACE_STD
176 #endif // _LIBCPP___MATH_TRAITS_H