diff options
| author | mikhnenko <[email protected]> | 2024-12-18 19:08:08 +0300 |
|---|---|---|
| committer | mikhnenko <[email protected]> | 2024-12-18 19:29:26 +0300 |
| commit | 7ed76959e6c06dbc4c249ce0f3b930463a6b65db (patch) | |
| tree | 0e9528cb7261812a5ae7ed177048721eaebf8ed0 /contrib/libs/cxxsupp/libcxx/include/__numeric/midpoint.h | |
| parent | 4c8e7f015711b5175d63e1a87cbd40c49ce7aa70 (diff) | |
libc++: Run clang-format from upstream and update to 9783f28cbb155e4a8d49c12e1c60ce14dcfaf0c7
commit_hash:ca4954fe054e5a7190ad11ab71bfc7ca0965bca2
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__numeric/midpoint.h')
| -rw-r--r-- | contrib/libs/cxxsupp/libcxx/include/__numeric/midpoint.h | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__numeric/midpoint.h b/contrib/libs/cxxsupp/libcxx/include/__numeric/midpoint.h index 57f19a35b4c..5d715c21d8e 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__numeric/midpoint.h +++ b/contrib/libs/cxxsupp/libcxx/include/__numeric/midpoint.h @@ -35,50 +35,46 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 template <class _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr -enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp> -midpoint(_Tp __a, _Tp __b) noexcept -_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK -{ - using _Up = make_unsigned_t<_Tp>; - constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1; +_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp> +midpoint(_Tp __a, _Tp __b) noexcept _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { + using _Up = make_unsigned_t<_Tp>; + constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1; - _Up __diff = _Up(__b) - _Up(__a); - _Up __sign_bit = __b < __a; + _Up __diff = _Up(__b) - _Up(__a); + _Up __sign_bit = __b < __a; - _Up __half_diff = (__diff / 2) + (__sign_bit << __bitshift) + (__sign_bit & __diff); + _Up __half_diff = (__diff / 2) + (__sign_bit << __bitshift) + (__sign_bit & __diff); - return __a + __half_diff; + return __a + __half_diff; } - template <class _Tp, enable_if_t<is_object_v<_Tp> && !is_void_v<_Tp> && (sizeof(_Tp) > 0), int> = 0> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept -{ - return __a + std::midpoint(ptrdiff_t(0), __b - __a); +_LIBCPP_HIDE_FROM_ABI constexpr _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept { + return __a + std::midpoint(ptrdiff_t(0), __b - __a); } - template <typename _Tp> _LIBCPP_HIDE_FROM_ABI constexpr int __sign(_Tp __val) { - return (_Tp(0) < __val) - (__val < _Tp(0)); + return (_Tp(0) < __val) - (__val < _Tp(0)); } template <typename _Fp> -_LIBCPP_HIDE_FROM_ABI constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; } +_LIBCPP_HIDE_FROM_ABI constexpr _Fp __fp_abs(_Fp __f) { + return __f >= 0 ? __f : -__f; +} template <class _Fp> -_LIBCPP_HIDE_FROM_ABI constexpr -enable_if_t<is_floating_point_v<_Fp>, _Fp> -midpoint(_Fp __a, _Fp __b) noexcept -{ - constexpr _Fp __lo = numeric_limits<_Fp>::min()*2; - constexpr _Fp __hi = numeric_limits<_Fp>::max()/2; - return std::__fp_abs(__a) <= __hi && std::__fp_abs(__b) <= __hi ? // typical case: overflow is impossible - (__a + __b)/2 : // always correctly rounded - std::__fp_abs(__a) < __lo ? __a + __b/2 : // not safe to halve a - std::__fp_abs(__b) < __lo ? __a/2 + __b : // not safe to halve b - __a/2 + __b/2; // otherwise correctly rounded +_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<is_floating_point_v<_Fp>, _Fp> midpoint(_Fp __a, _Fp __b) noexcept { + constexpr _Fp __lo = numeric_limits<_Fp>::min() * 2; + constexpr _Fp __hi = numeric_limits<_Fp>::max() / 2; + return std::__fp_abs(__a) <= __hi && std::__fp_abs(__b) <= __hi + ? // typical case: overflow is impossible + (__a + __b) / 2 + : // always correctly rounded + std::__fp_abs(__a) < __lo ? __a + __b / 2 : // not safe to halve a + std::__fp_abs(__b) < __lo ? __a / 2 + __b + : // not safe to halve b + __a / 2 + __b / 2; // otherwise correctly rounded } #endif // _LIBCPP_STD_VER >= 20 |
