tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
div_sat.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_NUMERIC_DIV_SAT_HPP
4#define TETL_NUMERIC_DIV_SAT_HPP
5
10
11namespace etl {
12
15template <builtin_integer Int>
16[[nodiscard]] constexpr auto div_sat(Int x, Int y) noexcept -> Int
17{
18 TETL_PRECONDITION(y != 0);
19 if constexpr (etl::is_signed_v<Int>) {
20 if (x == etl::numeric_limits<Int>::min() and y == Int(-1)) {
22 }
23 }
24 return x / y;
25}
26
27} // namespace etl
28
29#endif // TETL_NUMERIC_DIV_SAT_HPP
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto div_sat(Int x, Int y) noexcept -> Int
Computes the saturating division x / y.
Definition div_sat.hpp:16
Definition adjacent_find.hpp:8
constexpr bool is_signed_v
Definition is_signed.hpp:30
static constexpr auto max() noexcept
Definition numeric_limits.hpp:21
static constexpr auto min() noexcept
Definition numeric_limits.hpp:20