forked from cplusplus/fundamentals-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numeric.html
120 lines (106 loc) · 5.19 KB
/
numeric.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<cxx-clause id="numeric">
<h1>Numerics library</h1>
<cxx-section id="numeric.ops">
<h1>Generalized numeric operations</h1>
<cxx-section id="numeric.ops.overview">
<h1>Header <experimental/numeric> synopsis</h1>
<pre><code>#include <numeric>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
<cxx-ref insynopsis="" to="numeric.ops.gcd"></cxx-ref>
template<class M, class N>
constexpr common_type_t<M,N> gcd(M m, N n);
<cxx-ref insynopsis="" to="numeric.ops.lcm"></cxx-ref>
template<class M, class N>
constexpr common_type_t<M,N> lcm(M m, N n);
} // inline namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="numeric.ops.gcd">
<h1>Greatest common divisor</h1>
<cxx-function>
<cxx-signature>template<class M, class N>
constexpr common_type_t<M,N> gcd(M m, N n);</cxx-signature>
<cxx-requires>
<code>|m|</code> shall be representable as a value of type <code>M</code> and
<code>|n|</code> shall be representable as a value of type <code>N</code>.
<cxx-note>These requirements ensure, for example, that <code>gcd(m, m) = |m|</code> is representable as a value of type <code>M</code>.</cxx-note>
</cxx-requires>
<cxx-remarks>If either <code>M</code> or <code>N</code> is not an integer type, the program is ill-formed.</cxx-remarks>
<cxx-returns>
zero when <code>m</code> and <code>n</code> are both zero.
Otherwise, returns the greatest common divisor of <code>|m|</code> and <code>|n|</code>.</cxx-returns>
<cxx-throws>Nothing.</cxx-throws>
</cxx-function>
</cxx-section>
<cxx-section id="numeric.ops.lcm">
<h1>Least common multiple</h1>
<cxx-function>
<cxx-signature>template<class M, class N>
constexpr common_type_t<M,N> lcm(M m, N n);</cxx-signature>
<cxx-requires>
<code>|m|</code> shall be representable as a value of type <code>M</code> and
<code>|n|</code> shall be representable as a value of type <code>N</code>.
The least common multiple of <code>|m|</code> and <code>|n|</code>
shall be representable as a value of type <code>common_type_t<M,N></code>.
</cxx-requires>
<cxx-remarks>If either <code>M</code> or <code>N</code> is not an integer type, the program is ill-formed.</cxx-remarks>
<cxx-returns>
zero when either <code>m</code> or <code>n</code> is zero.
Otherwise, returns the least common multiple of <code>|m|</code> and <code>|n|</code>.
</cxx-returns>
<cxx-throws>Nothing.</cxx-throws>
</cxx-function>
</cxx-section>
</cxx-section>
<cxx-section id="rand">
<h1>Random number generation</h1>
<cxx-section id="rand.synopsis">
<h1>Header <code><experimental/random></code> synopsis</h1>
<pre><code>#include <random>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
<cxx-ref insynopsis="" to="rand.util.randint"></cxx-ref>
template <class IntType>
IntType randint(IntType a, IntType b);
void reseed();
void reseed(default_random_engine::result_type value);
} // inline namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="rand.util">
<h1>Utilities</h1>
<cxx-section id="rand.util.randint">
<h1>Function template <code>randint</code></h1>
<p>A separate <dfn>per-thread engine</dfn> of type <code>default_random_engine</code>
(<cxx-ref in="cxx" to="rand.predef"></cxx-ref>), initialized to an
unpredictable state, shall be maintained for each thread.</p>
<cxx-function>
<cxx-signature>template<class IntType>
IntType randint(IntType a, IntType b);</cxx-signature>
<cxx-requires><code>a</code> ≤ <code>b</code>.</cxx-requires>
<cxx-remarks>If the template argument does not meet the requirements
for <code>IntType</code> (<cxx-ref in="cxx" to="rand.req.genl"></cxx-ref>),
the program is ill-formed.</cxx-remarks>
<cxx-returns>A random integer <var>i</var>, <code>a</code> ≤ <var>i</var> ≤ <code>b</code>,
produced from a thread-local instance of <code>uniform_int_distribution<IntType></code>
(<cxx-ref in="cxx" to="rand.dist.uni.int"></cxx-ref>) invoked with the
per-thread engine.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-effects>Let <code>g</code> be the per-thread engine. The first
form sets <code>g</code> to an unpredictable state. The second form
invokes <code>g.seed(value)</code>.</cxx-effects>
<cxx-postconditions>Subsequent calls to <code>randint</code> do not
depend on values produced by <code>g</code> before calling <code>reseed</code>.
<cxx-note><code>reseed</code> also resets any instances of <code>uniform_int_distribution</code>
used by <code>randint</code>.</cxx-note></cxx-postconditions>
<cxx-signature>void reseed();</cxx-signature>
<cxx-signature>void reseed(default_random_engine::result_type value);</cxx-signature>
</cxx-section>
</cxx-section>
</cxx-clause>