From Jason Turner

[numeric.sat.func]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpsti23oo2/{from.md → to.md} +60 -0
tmp/tmpsti23oo2/{from.md → to.md} RENAMED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Arithmetic functions <a id="numeric.sat.func">[[numeric.sat.func]]</a>
2
+
3
+ In the following descriptions, an arithmetic operation is performed as a
4
+ mathematical operation with infinite range and then it is determined
5
+ whether the mathematical result fits into the result type.
6
+
7
+ ``` cpp
8
+ template<class T>
9
+ constexpr T add_sat(T x, T y) noexcept;
10
+ ```
11
+
12
+ *Constraints:* `T` is a signed or unsigned integer
13
+ type [[basic.fundamental]].
14
+
15
+ *Returns:* If `x` + `y` is representable as a value of type `T`,
16
+ `x` + `y`; otherwise, either the largest or smallest representable value
17
+ of type `T`, whichever is closer to the value of `x` + `y`.
18
+
19
+ ``` cpp
20
+ template<class T>
21
+ constexpr T sub_sat(T x, T y) noexcept;
22
+ ```
23
+
24
+ *Constraints:* `T` is a signed or unsigned integer
25
+ type [[basic.fundamental]].
26
+
27
+ *Returns:* If `x` - `y` is representable as a value of type `T`,
28
+ `x` - `y`; otherwise, either the largest or smallest representable value
29
+ of type `T`, whichever is closer to the value of `x` - `y`.
30
+
31
+ ``` cpp
32
+ template<class T>
33
+ constexpr T mul_sat(T x, T y) noexcept;
34
+ ```
35
+
36
+ *Constraints:* `T` is a signed or unsigned integer
37
+ type [[basic.fundamental]].
38
+
39
+ *Returns:* If `x` × `y` is representable as a value of type `T`,
40
+ `x` × `y`; otherwise, either the largest or smallest representable value
41
+ of type `T`, whichever is closer to the value of `x` × `y`.
42
+
43
+ ``` cpp
44
+ template<class T>
45
+ constexpr T div_sat(T x, T y) noexcept;
46
+ ```
47
+
48
+ *Constraints:* `T` is a signed or unsigned integer
49
+ type [[basic.fundamental]].
50
+
51
+ *Preconditions:* `y != 0` is `true`.
52
+
53
+ *Returns:* If `T` is a signed integer type and
54
+ `x == numeric_limits<T>::min() && y == -1` is `true`,
55
+ `numeric_limits<T>::max()`, otherwise, `x / y`.
56
+
57
+ *Remarks:* A function call expression that violates the precondition in
58
+ the *Preconditions* element is not a core constant
59
+ expression [[expr.const]].
60
+