30#ifndef _GLIBCXX_SAT_ARITH_H
31#define _GLIBCXX_SAT_ARITH_H 1
34#pragma GCC system_header
39#ifdef __glibcxx_saturation_arithmetic
44namespace std _GLIBCXX_VISIBILITY(default)
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _Tp>
requires __is_standard_integer<_Tp>::value
51 add_sat(_Tp __x, _Tp __y)
noexcept
54 if (!__builtin_add_overflow(__x, __y, &__z))
56 if constexpr (is_unsigned_v<_Tp>)
65 template<
typename _Tp>
requires __is_standard_integer<_Tp>::value
67 sub_sat(_Tp __x, _Tp __y)
noexcept
70 if (!__builtin_sub_overflow(__x, __y, &__z))
72 if constexpr (is_unsigned_v<_Tp>)
81 template<
typename _Tp>
requires __is_standard_integer<_Tp>::value
83 mul_sat(_Tp __x, _Tp __y)
noexcept
86 if (!__builtin_mul_overflow(__x, __y, &__z))
88 if constexpr (is_unsigned_v<_Tp>)
90 else if (__x < 0 != __y < 0)
97 template<
typename _Tp>
requires __is_standard_integer<_Tp>::value
99 div_sat(_Tp __x, _Tp __y)
noexcept
101 __glibcxx_assert(__y != 0);
102 if constexpr (is_signed_v<_Tp>)
109 template<
typename _Res,
typename _Tp>
110 requires __is_standard_integer<_Res>::value
111 && __is_standard_integer<_Tp>::value
113 saturate_cast(_Tp __x)
noexcept
119 if constexpr (is_signed_v<_Res> == is_signed_v<_Tp>)
121 if constexpr (__digits_R < __digits_T)
125 if (__x <
static_cast<_Tp
>(__min_Res))
127 else if (__x >
static_cast<_Tp
>(__max_Res))
131 else if constexpr (is_signed_v<_Tp>)
135 else if (make_unsigned_t<_Tp>(__x) > __max_Res)
140 if (__x > make_unsigned_t<_Res>(__max_Res))
143 return static_cast<_Res
>(__x);
146_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.