This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
[numeric.sat.cast]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#numeric.sat.cast)
### 26.10.17 Saturation arithmetic [[numeric.sat]](numeric.sat#cast)
#### 26.10.17.2 Casting [numeric.sat.cast]
[🔗](#lib:saturate_cast)
`template<class R, class T>
constexpr R saturate_cast(T x) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13488)
*Constraints*: R and T are signed or unsigned integer types ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13492)
*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[.](#2.sentence-1)

View File

@@ -0,0 +1,110 @@
[numeric.sat.func]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#numeric.sat.func)
### 26.10.17 Saturation arithmetic [[numeric.sat]](numeric.sat#func)
#### 26.10.17.1 Arithmetic functions [numeric.sat.func]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13392)
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[.](#1.sentence-1)
[🔗](#lib:add_sat)
`template<class T>
constexpr T add_sat(T x, T y) noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13404)
*Constraints*: T is a signed or unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13408)
*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[.](#3.sentence-1)
[🔗](#lib:sub_sat)
`template<class T>
constexpr T sub_sat(T x, T y) noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13422)
*Constraints*: T is a signed or unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13426)
*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[.](#5.sentence-1)
[🔗](#lib:mul_sat)
`template<class T>
constexpr T mul_sat(T x, T y) noexcept;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13440)
*Constraints*: T is a signed or unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13444)
*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[.](#7.sentence-1)
[🔗](#lib:div_sat)
`template<class T>
constexpr T div_sat(T x, T y) noexcept;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13458)
*Constraints*: T is a signed or unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13462)
*Preconditions*: y != 0 is true[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13466)
*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[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L13472)
*Remarks*: A function call expression
that violates the precondition in the *Preconditions* element
is not a core constant expression ([[expr.const]](expr.const "7.7Constant expressions"))[.](#11.sentence-1)