Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | //===----------------------------------------------------------------------===// |
|---|---|
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef _LIBCPP___CXX03___MATH_TRAITS_H |
| 10 | #define _LIBCPP___CXX03___MATH_TRAITS_H |
| 11 | |
| 12 | #include <__cxx03/__config> |
| 13 | #include <__cxx03/__type_traits/enable_if.h> |
| 14 | #include <__cxx03/__type_traits/is_arithmetic.h> |
| 15 | #include <__cxx03/__type_traits/is_floating_point.h> |
| 16 | #include <__cxx03/__type_traits/is_integral.h> |
| 17 | #include <__cxx03/__type_traits/is_signed.h> |
| 18 | #include <__cxx03/__type_traits/promote.h> |
| 19 | #include <__cxx03/limits> |
| 20 | |
| 21 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 22 | # pragma GCC system_header |
| 23 | #endif |
| 24 | |
| 25 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 26 | |
| 27 | namespace __math { |
| 28 | |
| 29 | // signbit |
| 30 | |
| 31 | template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0> |
| 32 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { |
| 33 | return __builtin_signbit(__x); |
| 34 | } |
| 35 | |
| 36 | template <class _A1, __enable_if_t<is_integral<_A1>::value && is_signed<_A1>::value, int> = 0> |
| 37 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { |
| 38 | return __x < 0; |
| 39 | } |
| 40 | |
| 41 | template <class _A1, __enable_if_t<is_integral<_A1>::value && !is_signed<_A1>::value, int> = 0> |
| 42 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | // isfinite |
| 47 | |
| 48 | template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0> |
| 49 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT { |
| 50 | return __builtin_isfinite((typename __promote<_A1>::type)__x); |
| 51 | } |
| 52 | |
| 53 | template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && !numeric_limits<_A1>::has_infinity, int> = 0> |
| 54 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT { |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT { return __builtin_isfinite(__x); } |
| 59 | |
| 60 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT { return __builtin_isfinite(__x); } |
| 61 | |
| 62 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT { |
| 63 | return __builtin_isfinite(__x); |
| 64 | } |
| 65 | |
| 66 | // isinf |
| 67 | |
| 68 | template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0> |
| 69 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT { |
| 70 | return __builtin_isinf((typename __promote<_A1>::type)__x); |
| 71 | } |
| 72 | |
| 73 | template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && !numeric_limits<_A1>::has_infinity, int> = 0> |
| 74 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) _NOEXCEPT { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | #ifdef _LIBCPP_PREFERRED_OVERLOAD |
| 79 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT { return __builtin_isinf(__x); } |
| 80 | |
| 81 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isinf(double __x) _NOEXCEPT { |
| 82 | return __builtin_isinf(__x); |
| 83 | } |
| 84 | |
| 85 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { return __builtin_isinf(__x); } |
| 86 | #endif |
| 87 | |
| 88 | // isnan |
| 89 | |
| 90 | template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0> |
| 91 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT { |
| 92 | return __builtin_isnan(__x); |
| 93 | } |
| 94 | |
| 95 | template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 96 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT { |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | #ifdef _LIBCPP_PREFERRED_OVERLOAD |
| 101 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT { return __builtin_isnan(__x); } |
| 102 | |
| 103 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool isnan(double __x) _NOEXCEPT { |
| 104 | return __builtin_isnan(__x); |
| 105 | } |
| 106 | |
| 107 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { return __builtin_isnan(__x); } |
| 108 | #endif |
| 109 | |
| 110 | // isnormal |
| 111 | |
| 112 | template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0> |
| 113 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { |
| 114 | return __builtin_isnormal(__x); |
| 115 | } |
| 116 | |
| 117 | template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0> |
| 118 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { |
| 119 | return __x != 0; |
| 120 | } |
| 121 | |
| 122 | // isgreater |
| 123 | |
| 124 | template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0> |
| 125 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT { |
| 126 | using type = typename __promote<_A1, _A2>::type; |
| 127 | return __builtin_isgreater((type)__x, (type)__y); |
| 128 | } |
| 129 | |
| 130 | // isgreaterequal |
| 131 | |
| 132 | template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0> |
| 133 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT { |
| 134 | using type = typename __promote<_A1, _A2>::type; |
| 135 | return __builtin_isgreaterequal((type)__x, (type)__y); |
| 136 | } |
| 137 | |
| 138 | // isless |
| 139 | |
| 140 | template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0> |
| 141 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT { |
| 142 | using type = typename __promote<_A1, _A2>::type; |
| 143 | return __builtin_isless((type)__x, (type)__y); |
| 144 | } |
| 145 | |
| 146 | // islessequal |
| 147 | |
| 148 | template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0> |
| 149 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT { |
| 150 | using type = typename __promote<_A1, _A2>::type; |
| 151 | return __builtin_islessequal((type)__x, (type)__y); |
| 152 | } |
| 153 | |
| 154 | // islessgreater |
| 155 | |
| 156 | template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0> |
| 157 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT { |
| 158 | using type = typename __promote<_A1, _A2>::type; |
| 159 | return __builtin_islessgreater((type)__x, (type)__y); |
| 160 | } |
| 161 | |
| 162 | // isunordered |
| 163 | |
| 164 | template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0> |
| 165 | _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT { |
| 166 | using type = typename __promote<_A1, _A2>::type; |
| 167 | return __builtin_isunordered((type)__x, (type)__y); |
| 168 | } |
| 169 | |
| 170 | } // namespace __math |
| 171 | |
| 172 | _LIBCPP_END_NAMESPACE_STD |
| 173 | |
| 174 | #endif // _LIBCPP___CXX03___MATH_TRAITS_H |
| 175 |
Warning: This file is not a C or C++ file. It does not have highlighting.
