#
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
template<class T> constexpr T sub_sat(T x, T y) noexcept;
Returns: If
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;
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]).
template<class R, class T> constexpr R saturate_cast(T x) noexcept;
Returns: If x is representable as a value of type R, x; otherwise, either the largest or smallest representable value of type R, whichever is closer to the value of x.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant