Files
2025-10-25 03:02:53 +03:00

3.7 KiB
Raw Permalink Blame History

[numeric.sat.func]

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]

1

#

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;

2

#

Constraints: T is a signed or unsigned integer type ([basic.fundamental]).

3

#

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 sub_sat(T x, T y) noexcept;

4

#

Constraints: T is a signed or unsigned integer type ([basic.fundamental]).

5

#

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 mul_sat(T x, T y) noexcept;

6

#

Constraints: T is a signed or unsigned integer type ([basic.fundamental]).

7

#

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;

8

#

Constraints: T is a signed or unsigned integer type ([basic.fundamental]).

9

#

Preconditions: y != 0 is true.

10

#

Returns: If T is a signed integer type and x == numeric_limits::min() && y == -1 is true,numeric_limits::max(), otherwise, x / y.

11

#

Remarks: A function call expression that violates the precondition in the Preconditions element is not a core constant expression ([expr.const]).