From Jason Turner

[numeric.sat]

Diff to HTML by rtfpessoa

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