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_signed_or_unsigned_integer<_Tp>::value
54 if (!__builtin_add_overflow(__x, __y, &__z))
56 if constexpr (is_unsigned_v<_Tp>)
65 template<
typename _Tp>
requires __is_signed_or_unsigned_integer<_Tp>::value
70 if (!__builtin_sub_overflow(__x, __y, &__z))
72 if constexpr (is_unsigned_v<_Tp>)
81 template<
typename _Tp>
requires __is_signed_or_unsigned_integer<_Tp>::value
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_signed_or_unsigned_integer<_Tp>::value
101 __glibcxx_assert(__y != 0);
102 if constexpr (is_signed_v<_Tp>)
109 template<
typename _Res,
typename _Tp>
110 requires __is_signed_or_unsigned_integer<_Res>::value
111 && __is_signed_or_unsigned_integer<_Tp>::value
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>)
143 return static_cast<_Res
>(__x);
146_GLIBCXX_END_NAMESPACE_VERSION
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
ISO C++ entities toplevel namespace is std.
::value constexpr _Tp saturating_add(_Tp __x, _Tp __y) noexcept
Add two integers, with saturation in case of overflow.
::value &&__is_signed_or_unsigned_integer< _Tp >::value constexpr _Res saturating_cast(_Tp __x) noexcept
Divide one integer by another, with saturation in case of overflow.
::value constexpr _Tp saturating_div(_Tp __x, _Tp __y) noexcept
Divide one integer by another, with saturation in case of overflow.
::value constexpr _Tp saturating_sub(_Tp __x, _Tp __y) noexcept
Subtract one integer from another, with saturation in case of overflow.
::value constexpr _Tp saturating_mul(_Tp __x, _Tp __y) noexcept
Multiply two integers, with saturation in case of overflow.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.