[numeric.sat.func] (original) (raw)
26 Algorithms library [algorithms]
26.10 Generalized numeric operations [numeric.ops]
26.10.17 Saturation arithmetic [numeric.sat]
26.10.17.1 Arithmetic functions [numeric.sat.func]
In the following descriptions, an arithmetic operation is performed as a mathematical operation with infinite range and then it is determined whether the mathematical result fits into the result type.
template<class T> constexpr T add_sat(T x, T y) noexcept;
Returns: If is representable as a value of type T, ; otherwise, either the largest or smallest representable value of type T, whichever is closer to the value of .
template<class T> constexpr T sub_sat(T x, T y) noexcept;
Returns: If is representable as a value of type T, ; otherwise, either the largest or smallest representable value of type T, whichever is closer to the value of .
template<class T> constexpr T mul_sat(T x, T y) noexcept;
Returns: If x ×y is representable as a value of type T, x ×y; otherwise, either the largest or smallest representable value of type T, whichever is closer to the value of x ×y.
template<class T> constexpr T div_sat(T x, T y) noexcept;
Preconditions: y != 0 is true.
Returns: If T is a signed integer type and x == numeric_limits<T>::min() && y == -1 is true,numeric_limits<T>::max(), otherwise, x / y.
Remarks: A function call expression that violates the precondition in the Preconditions element is not a core constant expression ([expr.const]).