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_ROUNDING_FUNCTIONS_H
0010 #define _LIBCPP___MATH_ROUNDING_FUNCTIONS_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_same.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 // ceil
0028 
0029 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); }
0030 
0031 template <class = int>
0032 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT {
0033   return __builtin_ceil(__x);
0034 }
0035 
0036 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT {
0037   return __builtin_ceill(__x);
0038 }
0039 
0040 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0041 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT {
0042   return __builtin_ceil((double)__x);
0043 }
0044 
0045 // floor
0046 
0047 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); }
0048 
0049 template <class = int>
0050 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT {
0051   return __builtin_floor(__x);
0052 }
0053 
0054 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT {
0055   return __builtin_floorl(__x);
0056 }
0057 
0058 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0059 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT {
0060   return __builtin_floor((double)__x);
0061 }
0062 
0063 // llrint
0064 
0065 inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT { return __builtin_llrintf(__x); }
0066 
0067 template <class = int>
0068 _LIBCPP_HIDE_FROM_ABI long long llrint(double __x) _NOEXCEPT {
0069   return __builtin_llrint(__x);
0070 }
0071 
0072 inline _LIBCPP_HIDE_FROM_ABI long long llrint(long double __x) _NOEXCEPT { return __builtin_llrintl(__x); }
0073 
0074 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0075 inline _LIBCPP_HIDE_FROM_ABI long long llrint(_A1 __x) _NOEXCEPT {
0076   return __builtin_llrint((double)__x);
0077 }
0078 
0079 // llround
0080 
0081 inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT { return __builtin_llroundf(__x); }
0082 
0083 template <class = int>
0084 _LIBCPP_HIDE_FROM_ABI long long llround(double __x) _NOEXCEPT {
0085   return __builtin_llround(__x);
0086 }
0087 
0088 inline _LIBCPP_HIDE_FROM_ABI long long llround(long double __x) _NOEXCEPT { return __builtin_llroundl(__x); }
0089 
0090 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0091 inline _LIBCPP_HIDE_FROM_ABI long long llround(_A1 __x) _NOEXCEPT {
0092   return __builtin_llround((double)__x);
0093 }
0094 
0095 // lrint
0096 
0097 inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT { return __builtin_lrintf(__x); }
0098 
0099 template <class = int>
0100 _LIBCPP_HIDE_FROM_ABI long lrint(double __x) _NOEXCEPT {
0101   return __builtin_lrint(__x);
0102 }
0103 
0104 inline _LIBCPP_HIDE_FROM_ABI long lrint(long double __x) _NOEXCEPT { return __builtin_lrintl(__x); }
0105 
0106 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0107 inline _LIBCPP_HIDE_FROM_ABI long lrint(_A1 __x) _NOEXCEPT {
0108   return __builtin_lrint((double)__x);
0109 }
0110 
0111 // lround
0112 
0113 inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT { return __builtin_lroundf(__x); }
0114 
0115 template <class = int>
0116 _LIBCPP_HIDE_FROM_ABI long lround(double __x) _NOEXCEPT {
0117   return __builtin_lround(__x);
0118 }
0119 
0120 inline _LIBCPP_HIDE_FROM_ABI long lround(long double __x) _NOEXCEPT { return __builtin_lroundl(__x); }
0121 
0122 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0123 inline _LIBCPP_HIDE_FROM_ABI long lround(_A1 __x) _NOEXCEPT {
0124   return __builtin_lround((double)__x);
0125 }
0126 
0127 // nearbyint
0128 
0129 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {
0130   return __builtin_nearbyintf(__x);
0131 }
0132 
0133 template <class = int>
0134 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT {
0135   return __builtin_nearbyint(__x);
0136 }
0137 
0138 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT {
0139   return __builtin_nearbyintl(__x);
0140 }
0141 
0142 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0143 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCEPT {
0144   return __builtin_nearbyint((double)__x);
0145 }
0146 
0147 // nextafter
0148 
0149 inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT { return __builtin_nextafterf(__x, __y); }
0150 
0151 template <class = int>
0152 _LIBCPP_HIDE_FROM_ABI double nextafter(double __x, double __y) _NOEXCEPT {
0153   return __builtin_nextafter(__x, __y);
0154 }
0155 
0156 inline _LIBCPP_HIDE_FROM_ABI long double nextafter(long double __x, long double __y) _NOEXCEPT {
0157   return __builtin_nextafterl(__x, __y);
0158 }
0159 
0160 template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
0161 inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type nextafter(_A1 __x, _A2 __y) _NOEXCEPT {
0162   using __result_type = typename __promote<_A1, _A2>::type;
0163   static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), "");
0164   return __math::nextafter((__result_type)__x, (__result_type)__y);
0165 }
0166 
0167 // nexttoward
0168 
0169 inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {
0170   return __builtin_nexttowardf(__x, __y);
0171 }
0172 
0173 template <class = int>
0174 _LIBCPP_HIDE_FROM_ABI double nexttoward(double __x, long double __y) _NOEXCEPT {
0175   return __builtin_nexttoward(__x, __y);
0176 }
0177 
0178 inline _LIBCPP_HIDE_FROM_ABI long double nexttoward(long double __x, long double __y) _NOEXCEPT {
0179   return __builtin_nexttowardl(__x, __y);
0180 }
0181 
0182 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0183 inline _LIBCPP_HIDE_FROM_ABI double nexttoward(_A1 __x, long double __y) _NOEXCEPT {
0184   return __builtin_nexttoward((double)__x, __y);
0185 }
0186 
0187 // rint
0188 
0189 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); }
0190 
0191 template <class = int>
0192 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT {
0193   return __builtin_rint(__x);
0194 }
0195 
0196 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT {
0197   return __builtin_rintl(__x);
0198 }
0199 
0200 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0201 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT {
0202   return __builtin_rint((double)__x);
0203 }
0204 
0205 // round
0206 
0207 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); }
0208 
0209 template <class = int>
0210 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT {
0211   return __builtin_round(__x);
0212 }
0213 
0214 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT {
0215   return __builtin_roundl(__x);
0216 }
0217 
0218 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0219 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT {
0220   return __builtin_round((double)__x);
0221 }
0222 
0223 // trunc
0224 
0225 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); }
0226 
0227 template <class = int>
0228 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT {
0229   return __builtin_trunc(__x);
0230 }
0231 
0232 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT {
0233   return __builtin_truncl(__x);
0234 }
0235 
0236 template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
0237 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double trunc(_A1 __x) _NOEXCEPT {
0238   return __builtin_trunc((double)__x);
0239 }
0240 
0241 } // namespace __math
0242 
0243 _LIBCPP_END_NAMESPACE_STD
0244 
0245 #endif // _LIBCPP___MATH_ROUNDING_FUNCTIONS_H