From Jason Turner

[numeric.ops]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpckzbunwf/{from.md → to.md} +94 -19
tmp/tmpckzbunwf/{from.md → to.md} RENAMED
@@ -6,20 +6,20 @@
6
  specify requirements throughout [[numeric.ops]] is
7
  intentional. — *end note*]
8
 
9
  ### Definitions <a id="numerics.defns">[[numerics.defns]]</a>
10
 
11
- Define `GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, ..., aN)` as follows:
12
 
13
  - `a1` when `N` is `1`, otherwise
14
- - `op(GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, ..., aK),`
15
- `\phantom{op(}GENERALIZED_NONCOMMUTATIVE_SUM(op, aM, ..., aN))` for
16
- any `K` where 1 < K+1 = M ≤ N.
17
 
18
- Define `GENERALIZED_SUM(op, a1, ..., aN)` as
19
- `GENERALIZED_NONCOMMUTATIVE_SUM(op, b1, ..., bN)`, where `b1, ..., bN`
20
- may be any permutation of `a1, ..., aN`.
21
 
22
  ### Accumulate <a id="accumulate">[[accumulate]]</a>
23
 
24
  ``` cpp
25
  template<class InputIterator, class T>
@@ -116,11 +116,11 @@ are convertible to `T`.
116
  - `T` meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
117
  requirements.
118
  - `binary_op` neither invalidates iterators or subranges, nor modifies
119
  elements in the range \[`first`, `last`\].
120
 
121
- *Returns:* *GENERALIZED_SUM*(binary_op, init, \*i, ...) for every `i` in
122
  \[`first`, `last`).
123
 
124
  *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
125
 
126
  [*Note 1*: The difference between `reduce` and `accumulate` is that
@@ -224,11 +224,11 @@ are convertible to `T`.
224
  `first2 + (last1 - first1)`\].
225
 
226
  *Returns:*
227
 
228
  ``` cpp
229
- GENERALIZED_SUM(binary_op1, init, binary_op2(*i, *(first2 + (i - first1))), ...)
230
  ```
231
 
232
  for every iterator `i` in \[`first1`, `last1`).
233
 
234
  *Complexity:* 𝑂(`last1 - first1`) applications each of `binary_op1` and
@@ -264,11 +264,11 @@ are convertible to `T`.
264
  elements in the range \[`first`, `last`\].
265
 
266
  *Returns:*
267
 
268
  ``` cpp
269
- GENERALIZED_SUM(binary_op, init, unary_op(*i), ...)
270
  ```
271
 
272
  for every iterator `i` in \[`first`, `last`).
273
 
274
  *Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
@@ -376,11 +376,11 @@ are convertible to `T`.
376
  *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
377
  through `result + K` the value of:
378
 
379
  ``` cpp
380
  GENERALIZED_NONCOMMUTATIVE_SUM(
381
- binary_op, init, *(first + 0), *(first + 1), ..., *(first + K - 1))
382
  ```
383
 
384
  *Returns:* The end of the resulting range beginning at `result`.
385
 
386
  *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
@@ -467,15 +467,14 @@ convertible to `U`.
467
 
468
  *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
469
  through `result + K` the value of
470
 
471
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
472
-     binary_op, init, \*(first + 0), \*(first + 1), ..., \*(first +
473
- K))
474
  if `init` is provided, or
475
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
476
-     binary_op, \*(first + 0), \*(first + 1), ..., \*(first + K))
477
  otherwise.
478
 
479
  *Returns:* The end of the resulting range beginning at `result`.
480
 
481
  *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
@@ -526,11 +525,11 @@ are convertible to `T`.
526
  through `result + K` the value of:
527
 
528
  ``` cpp
529
  GENERALIZED_NONCOMMUTATIVE_SUM(
530
  binary_op, init,
531
- unary_op(*(first + 0)), unary_op(*(first + 1)), ..., unary_op(*(first + K - 1)))
532
  ```
533
 
534
  *Returns:* The end of the resulting range beginning at `result`.
535
 
536
  *Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
@@ -603,16 +602,16 @@ are convertible to `T`; otherwise,
603
  *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
604
  through `result + K` the value of
605
 
606
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
607
      binary_op, init,
608
-     unary_op(\*(first + 0)), unary_op(\*(first + 1)), ...,
609
  unary_op(\*(first + K)))
610
  if `init` is provided, or
611
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
612
      binary_op,
613
-     unary_op(\*(first + 0)), unary_op(\*(first + 1)), ...,
614
  unary_op(\*(first + K)))
615
  otherwise.
616
 
617
  *Returns:* The end of the resulting range beginning at `result`.
618
 
@@ -682,12 +681,12 @@ every iterator `i` in \[`first + 1`, `last`) in order, creates an object
682
  `val` whose type is `T`, initializes it with `*i`, computes
683
  `binary_op(val, std::move(acc))`, assigns the result to
684
  `*(result + (i - first))`, and move assigns from `val` to `acc`.
685
 
686
  For the overloads with an `ExecutionPolicy` and a non-empty range,
687
- performs `*result = *first`. Then, for every `d` in
688
- `[1, last - first - 1]`, performs
689
  `*(result + d) = binary_op(*(first + d), *(first + (d - 1)))`.
690
 
691
  *Returns:* `result + (last - first)`.
692
 
693
  *Complexity:* Exactly `(last - first) - 1` applications of the binary
@@ -806,5 +805,81 @@ considered to be equivalent to a pointer to a hypothetical array element
806
  n for this purpose. — *end note*]
807
 
808
  *Returns:* A pointer to array element $i+\frac{j-i}{2}$ of `x`, where
809
  the result of the division is truncated towards zero.
810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  specify requirements throughout [[numeric.ops]] is
7
  intentional. — *end note*]
8
 
9
  ### Definitions <a id="numerics.defns">[[numerics.defns]]</a>
10
 
11
+ Define `GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, , aN)` as follows:
12
 
13
  - `a1` when `N` is `1`, otherwise
14
+ - `op(GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, , aK),`
15
+ `\phantom{op(}GENERALIZED_NONCOMMUTATIVE_SUM(op, aM, , aN))` for any
16
+ `K` where 1 < K+1 = M ≤ N.
17
 
18
+ Define `GENERALIZED_SUM(op, a1, , aN)` as
19
+ `GENERALIZED_NONCOMMUTATIVE_SUM(op, b1, , bN)`, where `b1, , bN` may
20
+ be any permutation of `a1, , aN`.
21
 
22
  ### Accumulate <a id="accumulate">[[accumulate]]</a>
23
 
24
  ``` cpp
25
  template<class InputIterator, class T>
 
116
  - `T` meets the *Cpp17MoveConstructible* ([[cpp17.moveconstructible]])
117
  requirements.
118
  - `binary_op` neither invalidates iterators or subranges, nor modifies
119
  elements in the range \[`first`, `last`\].
120
 
121
+ *Returns:* *GENERALIZED_SUM*(binary_op, init, \*i, ) for every `i` in
122
  \[`first`, `last`).
123
 
124
  *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
125
 
126
  [*Note 1*: The difference between `reduce` and `accumulate` is that
 
224
  `first2 + (last1 - first1)`\].
225
 
226
  *Returns:*
227
 
228
  ``` cpp
229
+ GENERALIZED_SUM(binary_op1, init, binary_op2(*i, *(first2 + (i - first1))), )
230
  ```
231
 
232
  for every iterator `i` in \[`first1`, `last1`).
233
 
234
  *Complexity:* 𝑂(`last1 - first1`) applications each of `binary_op1` and
 
264
  elements in the range \[`first`, `last`\].
265
 
266
  *Returns:*
267
 
268
  ``` cpp
269
+ GENERALIZED_SUM(binary_op, init, unary_op(*i), )
270
  ```
271
 
272
  for every iterator `i` in \[`first`, `last`).
273
 
274
  *Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
 
376
  *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
377
  through `result + K` the value of:
378
 
379
  ``` cpp
380
  GENERALIZED_NONCOMMUTATIVE_SUM(
381
+ binary_op, init, *(first + 0), *(first + 1), , *(first + K - 1))
382
  ```
383
 
384
  *Returns:* The end of the resulting range beginning at `result`.
385
 
386
  *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
 
467
 
468
  *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
469
  through `result + K` the value of
470
 
471
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
472
+     binary_op, init, \*(first + 0), \*(first + 1), , \*(first + K))
 
473
  if `init` is provided, or
474
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
475
+     binary_op, \*(first + 0), \*(first + 1), , \*(first + K))
476
  otherwise.
477
 
478
  *Returns:* The end of the resulting range beginning at `result`.
479
 
480
  *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
 
525
  through `result + K` the value of:
526
 
527
  ``` cpp
528
  GENERALIZED_NONCOMMUTATIVE_SUM(
529
  binary_op, init,
530
+ unary_op(*(first + 0)), unary_op(*(first + 1)), , unary_op(*(first + K - 1)))
531
  ```
532
 
533
  *Returns:* The end of the resulting range beginning at `result`.
534
 
535
  *Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
 
602
  *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
603
  through `result + K` the value of
604
 
605
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
606
      binary_op, init,
607
+     unary_op(\*(first + 0)), unary_op(\*(first + 1)), ,
608
  unary_op(\*(first + K)))
609
  if `init` is provided, or
610
  - *GENERALIZED_NONCOMMUTATIVE_SUM*(
611
      binary_op,
612
+     unary_op(\*(first + 0)), unary_op(\*(first + 1)), ,
613
  unary_op(\*(first + K)))
614
  otherwise.
615
 
616
  *Returns:* The end of the resulting range beginning at `result`.
617
 
 
681
  `val` whose type is `T`, initializes it with `*i`, computes
682
  `binary_op(val, std::move(acc))`, assigns the result to
683
  `*(result + (i - first))`, and move assigns from `val` to `acc`.
684
 
685
  For the overloads with an `ExecutionPolicy` and a non-empty range,
686
+ performs `*result = *first`. Then, for every `d` in \[`1`,
687
+ `last - first - 1`\], performs
688
  `*(result + d) = binary_op(*(first + d), *(first + (d - 1)))`.
689
 
690
  *Returns:* `result + (last - first)`.
691
 
692
  *Complexity:* Exactly `(last - first) - 1` applications of the binary
 
805
  n for this purpose. — *end note*]
806
 
807
  *Returns:* A pointer to array element $i+\frac{j-i}{2}$ of `x`, where
808
  the result of the division is truncated towards zero.
809
 
810
+ ### Saturation arithmetic <a id="numeric.sat">[[numeric.sat]]</a>
811
+
812
+ #### Arithmetic functions <a id="numeric.sat.func">[[numeric.sat.func]]</a>
813
+
814
+ In the following descriptions, an arithmetic operation is performed as a
815
+ mathematical operation with infinite range and then it is determined
816
+ whether the mathematical result fits into the result type.
817
+
818
+ ``` cpp
819
+ template<class T>
820
+ constexpr T add_sat(T x, T y) noexcept;
821
+ ```
822
+
823
+ *Constraints:* `T` is a signed or unsigned integer
824
+ type [[basic.fundamental]].
825
+
826
+ *Returns:* If `x` + `y` is representable as a value of type `T`,
827
+ `x` + `y`; otherwise, either the largest or smallest representable value
828
+ of type `T`, whichever is closer to the value of `x` + `y`.
829
+
830
+ ``` cpp
831
+ template<class T>
832
+ constexpr T sub_sat(T x, T y) noexcept;
833
+ ```
834
+
835
+ *Constraints:* `T` is a signed or unsigned integer
836
+ type [[basic.fundamental]].
837
+
838
+ *Returns:* If `x` - `y` is representable as a value of type `T`,
839
+ `x` - `y`; otherwise, either the largest or smallest representable value
840
+ of type `T`, whichever is closer to the value of `x` - `y`.
841
+
842
+ ``` cpp
843
+ template<class T>
844
+ constexpr T mul_sat(T x, T y) noexcept;
845
+ ```
846
+
847
+ *Constraints:* `T` is a signed or unsigned integer
848
+ type [[basic.fundamental]].
849
+
850
+ *Returns:* If `x` × `y` is representable as a value of type `T`,
851
+ `x` × `y`; otherwise, either the largest or smallest representable value
852
+ of type `T`, whichever is closer to the value of `x` × `y`.
853
+
854
+ ``` cpp
855
+ template<class T>
856
+ constexpr T div_sat(T x, T y) noexcept;
857
+ ```
858
+
859
+ *Constraints:* `T` is a signed or unsigned integer
860
+ type [[basic.fundamental]].
861
+
862
+ *Preconditions:* `y != 0` is `true`.
863
+
864
+ *Returns:* If `T` is a signed integer type and
865
+ `x == numeric_limits<T>::min() && y == -1` is `true`,
866
+ `numeric_limits<T>::max()`, otherwise, `x / y`.
867
+
868
+ *Remarks:* A function call expression that violates the precondition in
869
+ the *Preconditions* element is not a core constant
870
+ expression [[expr.const]].
871
+
872
+ #### Casting <a id="numeric.sat.cast">[[numeric.sat.cast]]</a>
873
+
874
+ ``` cpp
875
+ template<class R, class T>
876
+ constexpr R saturate_cast(T x) noexcept;
877
+ ```
878
+
879
+ *Constraints:* `R` and `T` are signed or unsigned integer
880
+ types [[basic.fundamental]].
881
+
882
+ *Returns:* If `x` is representable as a value of type `R`, `x`;
883
+ otherwise, either the largest or smallest representable value of type
884
+ `R`, whichever is closer to the value of `x`.
885
+