3#ifndef TETL_NUMERIC_ADD_SAT_HPP
4#define TETL_NUMERIC_ADD_SAT_HPP
20template <etl::builtin_
integer Int>
21[[nodiscard]]
constexpr auto add_sat_fallback(Int x, Int y)
noexcept -> Int
26 if constexpr (
sizeof(Int) <
sizeof(int) and etl::same_as<
decltype(x + y),
int>) {
28 }
else if constexpr (
sizeof(Int) <
sizeof(unsigned) and etl::same_as<
decltype(x + y),
unsigned>) {
55template <etl::builtin_
integer Int>
56[[nodiscard]]
constexpr auto add_sat(Int x, Int y)
noexcept -> Int
58#if defined(__GNUC__) or defined(__clang__)
62 if (Int sum{0}; not __builtin_add_overflow(x, y, &sum)) {
74 return etl::detail::add_sat_fallback(x, y);
constexpr auto clamp(Type const &v, Type const &lo, Type const &hi, Compare comp) -> Type const &
If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise r...
Definition clamp.hpp:17
constexpr auto min(Type const &a, Type const &b, Compare comp) noexcept -> Type const &
Returns the smaller of a and b, using a compare function.
Definition min.hpp:13
constexpr auto max(Type const &a, Type const &b, Compare comp) noexcept -> Type const &
Returns the greater of a and b, using a compare function.
Definition max.hpp:13
constexpr auto add_sat(Int x, Int y) noexcept -> Int
Definition add_sat.hpp:56
Definition adjacent_find.hpp:8
constexpr bool is_signed_v
Definition is_signed.hpp:30
TETL_BUILTIN_INT32 int32_t
Signed integer type with width of exactly 32 bits.
Definition int_t.hpp:17
TETL_BUILTIN_INT64 int64_t
Signed integer type with width of exactly 64 bits.
Definition int_t.hpp:20
TETL_BUILTIN_UINT64 uint64_t
Unsigned integer type with width of exactly 64 bits.
Definition uint_t.hpp:20
constexpr bool is_unsigned_v
Definition is_unsigned.hpp:33
TETL_BUILTIN_UINT32 uint32_t
Unsigned integer type with width of exactly 32 bits.
Definition uint_t.hpp:17
static constexpr auto max() noexcept
Definition numeric_limits.hpp:21
static constexpr auto min() noexcept
Definition numeric_limits.hpp:20