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___ALGORITHM_HALF_POSITIVE_H
10 #define _LIBCPP___ALGORITHM_HALF_POSITIVE_H
13 #include <type_traits>
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 #pragma GCC system_header
19 _LIBCPP_BEGIN_NAMESPACE_STD
21 // Perform division by two quickly for positive integers (llvm.org/PR39129)
23 template <typename _Integral>
24 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
27 is_integral<_Integral>::value,
30 __half_positive(_Integral __value)
32 return static_cast<_Integral>(static_cast<typename make_unsigned<_Integral>::type>(__value) / 2);
35 template <typename _Tp>
36 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
39 !is_integral<_Tp>::value,
42 __half_positive(_Tp __value)
47 _LIBCPP_END_NAMESPACE_STD
49 #endif // _LIBCPP___ALGORITHM_HALF_POSITIVE_H