Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:55

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___MATH_TRAITS_H
0010 #define _LIBCPP___MATH_TRAITS_H
0011 
0012 #include <__config>
0013 #include <__type_traits/enable_if.h>
0014 #include <__type_traits/is_arithmetic.h>
0015 #include <__type_traits/is_integral.h>
0016 #include <__type_traits/is_signed.h>
0017 #include <__type_traits/promote.h>
0018 
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 #  pragma GCC system_header
0021 #endif
0022 
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024 
0025 namespace __math {
0026 
0027 // signbit
0028 
0029 // TODO(LLVM 22): Remove conditional once support for Clang 19 is dropped.
0030 #if defined(_LIBCPP_COMPILER_GCC) || __has_constexpr_builtin(__builtin_signbit)
0031 #  define _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_CONSTEXPR_SINCE_CXX23
0032 #else
0033 #  define _LIBCPP_SIGNBIT_CONSTEXPR
0034 #endif
0035 
0036 // The universal C runtime (UCRT) in the WinSDK provides floating point overloads
0037 // for std::signbit(). By defining our overloads as templates, we can work around
0038 // this issue as templates are less preferred than non-template functions.
0039 template <class = void>
0040 [[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(float __x) _NOEXCEPT {
0041   return __builtin_signbit(__x);
0042 }
0043 
0044 template <class = void>
0045 [[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(double __x) _NOEXCEPT {
0046   return __builtin_signbit(__x);
0047 }
0048 
0049 template <class = void>
0050 [[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(long double __x) _NOEXCEPT {
0051   return __builtin_signbit(__x);
0052 }
0053 
0054 template <class _A1, __enable_if_t<is_integral<_A1>::value && is_signed<_A1>::value, int> = 0>
0055 [[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
0056   return __x < 0;
0057 }
0058 
0059 template <class _A1, __enable_if_t<is_integral<_A1>::value && !is_signed<_A1>::value, int> = 0>
0060 [[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
0061   return false;
0062 }
0063 
0064 // isfinite
0065 
0066 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0067 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT {
0068   return true;
0069 }
0070 
0071 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT {
0072   return __builtin_isfinite(__x);
0073 }
0074 
0075 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT {
0076   return __builtin_isfinite(__x);
0077 }
0078 
0079 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT {
0080   return __builtin_isfinite(__x);
0081 }
0082 
0083 // isinf
0084 
0085 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0086 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) _NOEXCEPT {
0087   return false;
0088 }
0089 
0090 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT {
0091   return __builtin_isinf(__x);
0092 }
0093 
0094 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
0095 #ifdef _LIBCPP_PREFERRED_OVERLOAD
0096 _LIBCPP_PREFERRED_OVERLOAD
0097 #endif
0098     bool
0099     isinf(double __x) _NOEXCEPT {
0100   return __builtin_isinf(__x);
0101 }
0102 
0103 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT {
0104   return __builtin_isinf(__x);
0105 }
0106 
0107 // isnan
0108 
0109 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0110 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT {
0111   return false;
0112 }
0113 
0114 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT {
0115   return __builtin_isnan(__x);
0116 }
0117 
0118 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI
0119 #ifdef _LIBCPP_PREFERRED_OVERLOAD
0120 _LIBCPP_PREFERRED_OVERLOAD
0121 #endif
0122     bool
0123     isnan(double __x) _NOEXCEPT {
0124   return __builtin_isnan(__x);
0125 }
0126 
0127 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT {
0128   return __builtin_isnan(__x);
0129 }
0130 
0131 // isnormal
0132 
0133 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0134 [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
0135   return __x != 0;
0136 }
0137 
0138 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(float __x) _NOEXCEPT {
0139   return __builtin_isnormal(__x);
0140 }
0141 
0142 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(double __x) _NOEXCEPT {
0143   return __builtin_isnormal(__x);
0144 }
0145 
0146 [[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(long double __x) _NOEXCEPT {
0147   return __builtin_isnormal(__x);
0148 }
0149 
0150 // isgreater
0151 
0152 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
0153 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
0154   using type = typename __promote<_A1, _A2>::type;
0155   return __builtin_isgreater((type)__x, (type)__y);
0156 }
0157 
0158 // isgreaterequal
0159 
0160 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
0161 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
0162   using type = typename __promote<_A1, _A2>::type;
0163   return __builtin_isgreaterequal((type)__x, (type)__y);
0164 }
0165 
0166 // isless
0167 
0168 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
0169 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
0170   using type = typename __promote<_A1, _A2>::type;
0171   return __builtin_isless((type)__x, (type)__y);
0172 }
0173 
0174 // islessequal
0175 
0176 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
0177 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
0178   using type = typename __promote<_A1, _A2>::type;
0179   return __builtin_islessequal((type)__x, (type)__y);
0180 }
0181 
0182 // islessgreater
0183 
0184 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
0185 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
0186   using type = typename __promote<_A1, _A2>::type;
0187   return __builtin_islessgreater((type)__x, (type)__y);
0188 }
0189 
0190 // isunordered
0191 
0192 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
0193 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
0194   using type = typename __promote<_A1, _A2>::type;
0195   return __builtin_isunordered((type)__x, (type)__y);
0196 }
0197 
0198 } // namespace __math
0199 
0200 _LIBCPP_END_NAMESPACE_STD
0201 
0202 #endif // _LIBCPP___MATH_TRAITS_H