- tmp/tmpx1kzy_5v/{from.md → to.md} +742 -872
tmp/tmpx1kzy_5v/{from.md → to.md}
RENAMED
|
@@ -15,11 +15,10 @@ floating-point types, as summarized in [[numerics.summary]].
|
|
| 15 |
| Subclause | | Header |
|
| 16 |
| ------------------------ | ----------------------------------------------- | ---------------------- |
|
| 17 |
| [[numeric.requirements]] | Requirements | |
|
| 18 |
| [[cfenv]] | Floating-point environment | `<cfenv>` |
|
| 19 |
| [[complex.numbers]] | Complex numbers | `<complex>` |
|
| 20 |
-
| [[bit]] | Bit manipulation | `<bit>` |
|
| 21 |
| [[rand]] | Random number generation | `<random>` |
|
| 22 |
| [[numarray]] | Numeric arrays | `<valarray>` |
|
| 23 |
| [[c.math]] | Mathematical functions for floating-point types | `<cmath>`, `<cstdlib>` |
|
| 24 |
| [[numbers]] | Numbers | `<numbers>` |
|
| 25 |
|
|
@@ -98,35 +97,40 @@ floating-point status flags, set floating-point control modes, or run
|
|
| 98 |
under non-default mode settings. If the pragma is used to enable control
|
| 99 |
over the floating-point environment, this document does not specify the
|
| 100 |
effect on floating-point evaluation in constant
|
| 101 |
expressions. — *end note*]
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
The floating-point environment has thread storage duration
|
| 104 |
[[basic.stc.thread]]. The initial state for a thread’s floating-point
|
| 105 |
environment is the state of the floating-point environment of the thread
|
| 106 |
that constructs the corresponding `thread` object
|
| 107 |
[[thread.thread.class]] or `jthread` object [[thread.jthread.class]] at
|
| 108 |
the time it constructed the object.
|
| 109 |
|
| 110 |
-
[*Note
|
| 111 |
the parent thread at the time of the child’s creation. — *end note*]
|
| 112 |
|
| 113 |
A separate floating-point environment is maintained for each thread.
|
| 114 |
Each function accesses the environment corresponding to its calling
|
| 115 |
thread.
|
| 116 |
|
| 117 |
-
See also: ISO C 7.6
|
| 118 |
-
|
| 119 |
## Complex numbers <a id="complex.numbers">[[complex.numbers]]</a>
|
| 120 |
|
|
|
|
|
|
|
| 121 |
The header `<complex>` defines a class template, and numerous functions
|
| 122 |
for representing and manipulating complex numbers.
|
| 123 |
|
| 124 |
-
The effect of instantiating the template `complex` for any type
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
| 128 |
|
| 129 |
If the result of a function is not mathematically defined or not in the
|
| 130 |
range of representable values for its type, the behavior is undefined.
|
| 131 |
|
| 132 |
If `z` is an lvalue of type cv `complex<T>` then:
|
|
@@ -150,15 +154,10 @@ expression `a[i]` is well-defined for an integer expression `i`, then:
|
|
| 150 |
``` cpp
|
| 151 |
namespace std {
|
| 152 |
// [complex], class template complex
|
| 153 |
template<class T> class complex;
|
| 154 |
|
| 155 |
-
// [complex.special], specializations
|
| 156 |
-
template<> class complex<float>;
|
| 157 |
-
template<> class complex<double>;
|
| 158 |
-
template<> class complex<long double>;
|
| 159 |
-
|
| 160 |
// [complex.ops], operators
|
| 161 |
template<class T> constexpr complex<T> operator+(const complex<T>&, const complex<T>&);
|
| 162 |
template<class T> constexpr complex<T> operator+(const complex<T>&, const T&);
|
| 163 |
template<class T> constexpr complex<T> operator+(const T&, const complex<T>&);
|
| 164 |
|
|
@@ -244,12 +243,12 @@ namespace std {
|
|
| 244 |
template<class T> class complex {
|
| 245 |
public:
|
| 246 |
using value_type = T;
|
| 247 |
|
| 248 |
constexpr complex(const T& re = T(), const T& im = T());
|
| 249 |
-
constexpr complex(const complex&);
|
| 250 |
-
template<class X> constexpr complex(const complex<X>&);
|
| 251 |
|
| 252 |
constexpr T real() const;
|
| 253 |
constexpr void real(T);
|
| 254 |
constexpr T imag() const;
|
| 255 |
constexpr void imag(T);
|
|
@@ -271,108 +270,29 @@ namespace std {
|
|
| 271 |
```
|
| 272 |
|
| 273 |
The class `complex` describes an object that can store the Cartesian
|
| 274 |
components, `real()` and `imag()`, of a complex number.
|
| 275 |
|
| 276 |
-
### Specializations <a id="complex.special">[[complex.special]]</a>
|
| 277 |
-
|
| 278 |
-
``` cpp
|
| 279 |
-
namespace std {
|
| 280 |
-
template<> class complex<float> {
|
| 281 |
-
public:
|
| 282 |
-
using value_type = float;
|
| 283 |
-
|
| 284 |
-
constexpr complex(float re = 0.0f, float im = 0.0f);
|
| 285 |
-
constexpr complex(const complex<float>&) = default;
|
| 286 |
-
constexpr explicit complex(const complex<double>&);
|
| 287 |
-
constexpr explicit complex(const complex<long double>&);
|
| 288 |
-
|
| 289 |
-
constexpr float real() const;
|
| 290 |
-
constexpr void real(float);
|
| 291 |
-
constexpr float imag() const;
|
| 292 |
-
constexpr void imag(float);
|
| 293 |
-
|
| 294 |
-
constexpr complex& operator= (float);
|
| 295 |
-
constexpr complex& operator+=(float);
|
| 296 |
-
constexpr complex& operator-=(float);
|
| 297 |
-
constexpr complex& operator*=(float);
|
| 298 |
-
constexpr complex& operator/=(float);
|
| 299 |
-
|
| 300 |
-
constexpr complex& operator=(const complex&);
|
| 301 |
-
template<class X> constexpr complex& operator= (const complex<X>&);
|
| 302 |
-
template<class X> constexpr complex& operator+=(const complex<X>&);
|
| 303 |
-
template<class X> constexpr complex& operator-=(const complex<X>&);
|
| 304 |
-
template<class X> constexpr complex& operator*=(const complex<X>&);
|
| 305 |
-
template<class X> constexpr complex& operator/=(const complex<X>&);
|
| 306 |
-
};
|
| 307 |
-
|
| 308 |
-
template<> class complex<double> {
|
| 309 |
-
public:
|
| 310 |
-
using value_type = double;
|
| 311 |
-
|
| 312 |
-
constexpr complex(double re = 0.0, double im = 0.0);
|
| 313 |
-
constexpr complex(const complex<float>&);
|
| 314 |
-
constexpr complex(const complex<double>&) = default;
|
| 315 |
-
constexpr explicit complex(const complex<long double>&);
|
| 316 |
-
|
| 317 |
-
constexpr double real() const;
|
| 318 |
-
constexpr void real(double);
|
| 319 |
-
constexpr double imag() const;
|
| 320 |
-
constexpr void imag(double);
|
| 321 |
-
|
| 322 |
-
constexpr complex& operator= (double);
|
| 323 |
-
constexpr complex& operator+=(double);
|
| 324 |
-
constexpr complex& operator-=(double);
|
| 325 |
-
constexpr complex& operator*=(double);
|
| 326 |
-
constexpr complex& operator/=(double);
|
| 327 |
-
|
| 328 |
-
constexpr complex& operator=(const complex&);
|
| 329 |
-
template<class X> constexpr complex& operator= (const complex<X>&);
|
| 330 |
-
template<class X> constexpr complex& operator+=(const complex<X>&);
|
| 331 |
-
template<class X> constexpr complex& operator-=(const complex<X>&);
|
| 332 |
-
template<class X> constexpr complex& operator*=(const complex<X>&);
|
| 333 |
-
template<class X> constexpr complex& operator/=(const complex<X>&);
|
| 334 |
-
};
|
| 335 |
-
|
| 336 |
-
template<> class complex<long double> {
|
| 337 |
-
public:
|
| 338 |
-
using value_type = long double;
|
| 339 |
-
|
| 340 |
-
constexpr complex(long double re = 0.0L, long double im = 0.0L);
|
| 341 |
-
constexpr complex(const complex<float>&);
|
| 342 |
-
constexpr complex(const complex<double>&);
|
| 343 |
-
constexpr complex(const complex<long double>&) = default;
|
| 344 |
-
|
| 345 |
-
constexpr long double real() const;
|
| 346 |
-
constexpr void real(long double);
|
| 347 |
-
constexpr long double imag() const;
|
| 348 |
-
constexpr void imag(long double);
|
| 349 |
-
|
| 350 |
-
constexpr complex& operator= (long double);
|
| 351 |
-
constexpr complex& operator+=(long double);
|
| 352 |
-
constexpr complex& operator-=(long double);
|
| 353 |
-
constexpr complex& operator*=(long double);
|
| 354 |
-
constexpr complex& operator/=(long double);
|
| 355 |
-
|
| 356 |
-
constexpr complex& operator=(const complex&);
|
| 357 |
-
template<class X> constexpr complex& operator= (const complex<X>&);
|
| 358 |
-
template<class X> constexpr complex& operator+=(const complex<X>&);
|
| 359 |
-
template<class X> constexpr complex& operator-=(const complex<X>&);
|
| 360 |
-
template<class X> constexpr complex& operator*=(const complex<X>&);
|
| 361 |
-
template<class X> constexpr complex& operator/=(const complex<X>&);
|
| 362 |
-
};
|
| 363 |
-
}
|
| 364 |
-
```
|
| 365 |
-
|
| 366 |
### Member functions <a id="complex.members">[[complex.members]]</a>
|
| 367 |
|
| 368 |
``` cpp
|
| 369 |
-
|
| 370 |
```
|
| 371 |
|
| 372 |
*Ensures:* `real() == re && imag() == im` is `true`.
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
``` cpp
|
| 375 |
constexpr T real() const;
|
| 376 |
```
|
| 377 |
|
| 378 |
*Returns:* The value of the real component.
|
|
@@ -558,11 +478,11 @@ were implemented as follows:
|
|
| 558 |
``` cpp
|
| 559 |
basic_ostringstream<charT, traits> s;
|
| 560 |
s.flags(o.flags());
|
| 561 |
s.imbue(o.getloc());
|
| 562 |
s.precision(o.precision());
|
| 563 |
-
s << '(' << x.real() <<
|
| 564 |
return o << s.str();
|
| 565 |
```
|
| 566 |
|
| 567 |
[*Note 1*: In a locale in which comma is used as a decimal point
|
| 568 |
character, the use of comma as a field separator can be ambiguous.
|
|
@@ -781,28 +701,20 @@ imag real
|
|
| 781 |
|
| 782 |
where `norm`, `conj`, `imag`, and `real` are `constexpr` overloads.
|
| 783 |
|
| 784 |
The additional overloads shall be sufficient to ensure:
|
| 785 |
|
| 786 |
-
- If the argument has type `
|
| 787 |
-
`complex<
|
| 788 |
-
- Otherwise, if the argument has
|
| 789 |
-
|
| 790 |
-
- Otherwise, if the argument has type `float`, then it is effectively
|
| 791 |
-
cast to `complex<float>`.
|
| 792 |
|
| 793 |
-
Function template `pow`
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
`complex<long double>`.
|
| 799 |
-
- Otherwise, if either argument has type `complex<double>`, `double`, or
|
| 800 |
-
an integer type, then both arguments are effectively cast to
|
| 801 |
-
`complex<double>`.
|
| 802 |
-
- Otherwise, if either argument has type `complex<float>` or `float`,
|
| 803 |
-
then both arguments are effectively cast to `complex<float>`.
|
| 804 |
|
| 805 |
### Suffixes for complex number literals <a id="complex.literals">[[complex.literals]]</a>
|
| 806 |
|
| 807 |
This subclause describes literal suffixes for constructing complex
|
| 808 |
number literals. The suffixes `i`, `il`, and `if` create complex numbers
|
|
@@ -829,265 +741,15 @@ constexpr complex<float> operator""if(long double d);
|
|
| 829 |
constexpr complex<float> operator""if(unsigned long long d);
|
| 830 |
```
|
| 831 |
|
| 832 |
*Returns:* `complex<float>{0.0f, static_cast<float>(d)}`.
|
| 833 |
|
| 834 |
-
## Bit manipulation <a id="bit">[[bit]]</a>
|
| 835 |
-
|
| 836 |
-
### General <a id="bit.general">[[bit.general]]</a>
|
| 837 |
-
|
| 838 |
-
The header `<bit>` provides components to access, manipulate and process
|
| 839 |
-
both individual bits and bit sequences.
|
| 840 |
-
|
| 841 |
-
### Header `<bit>` synopsis <a id="bit.syn">[[bit.syn]]</a>
|
| 842 |
-
|
| 843 |
-
``` cpp
|
| 844 |
-
namespace std {
|
| 845 |
-
// [bit.cast], bit_cast
|
| 846 |
-
template<class To, class From>
|
| 847 |
-
constexpr To bit_cast(const From& from) noexcept;
|
| 848 |
-
|
| 849 |
-
// [bit.pow.two], integral powers of 2
|
| 850 |
-
template<class T>
|
| 851 |
-
constexpr bool has_single_bit(T x) noexcept;
|
| 852 |
-
template<class T>
|
| 853 |
-
constexpr T bit_ceil(T x);
|
| 854 |
-
template<class T>
|
| 855 |
-
constexpr T bit_floor(T x) noexcept;
|
| 856 |
-
template<class T>
|
| 857 |
-
constexpr T bit_width(T x) noexcept;
|
| 858 |
-
|
| 859 |
-
// [bit.rotate], rotating
|
| 860 |
-
template<class T>
|
| 861 |
-
[[nodiscard]] constexpr T rotl(T x, int s) noexcept;
|
| 862 |
-
template<class T>
|
| 863 |
-
[[nodiscard]] constexpr T rotr(T x, int s) noexcept;
|
| 864 |
-
|
| 865 |
-
// [bit.count], counting
|
| 866 |
-
template<class T>
|
| 867 |
-
constexpr int countl_zero(T x) noexcept;
|
| 868 |
-
template<class T>
|
| 869 |
-
constexpr int countl_one(T x) noexcept;
|
| 870 |
-
template<class T>
|
| 871 |
-
constexpr int countr_zero(T x) noexcept;
|
| 872 |
-
template<class T>
|
| 873 |
-
constexpr int countr_one(T x) noexcept;
|
| 874 |
-
template<class T>
|
| 875 |
-
constexpr int popcount(T x) noexcept;
|
| 876 |
-
|
| 877 |
-
// [bit.endian], endian
|
| 878 |
-
enum class endian {
|
| 879 |
-
little = see below,
|
| 880 |
-
big = see below,
|
| 881 |
-
native = see below
|
| 882 |
-
};
|
| 883 |
-
}
|
| 884 |
-
```
|
| 885 |
-
|
| 886 |
-
### Function template `bit_cast` <a id="bit.cast">[[bit.cast]]</a>
|
| 887 |
-
|
| 888 |
-
``` cpp
|
| 889 |
-
template<class To, class From>
|
| 890 |
-
constexpr To bit_cast(const From& from) noexcept;
|
| 891 |
-
```
|
| 892 |
-
|
| 893 |
-
*Constraints:*
|
| 894 |
-
|
| 895 |
-
- `sizeof(To) == sizeof(From)` is `true`;
|
| 896 |
-
- `is_trivially_copyable_v<To>` is `true`; and
|
| 897 |
-
- `is_trivially_copyable_v<From>` is `true`.
|
| 898 |
-
|
| 899 |
-
*Returns:* An object of type `To`. Implicitly creates objects nested
|
| 900 |
-
within the result [[intro.object]]. Each bit of the value representation
|
| 901 |
-
of the result is equal to the corresponding bit in the object
|
| 902 |
-
representation of `from`. Padding bits of the result are unspecified.
|
| 903 |
-
For the result and each object created within it, if there is no value
|
| 904 |
-
of the object’s type corresponding to the value representation produced,
|
| 905 |
-
the behavior is undefined. If there are multiple such values, which
|
| 906 |
-
value is produced is unspecified.
|
| 907 |
-
|
| 908 |
-
*Remarks:* This function is `constexpr` if and only if `To`, `From`, and
|
| 909 |
-
the types of all subobjects of `To` and `From` are types `T` such that:
|
| 910 |
-
|
| 911 |
-
- `is_union_v<T>` is `false`;
|
| 912 |
-
- `is_pointer_v<T>` is `false`;
|
| 913 |
-
- `is_member_pointer_v<T>` is `false`;
|
| 914 |
-
- `is_volatile_v<T>` is `false`; and
|
| 915 |
-
- `T` has no non-static data members of reference type.
|
| 916 |
-
|
| 917 |
-
### Integral powers of 2 <a id="bit.pow.two">[[bit.pow.two]]</a>
|
| 918 |
-
|
| 919 |
-
``` cpp
|
| 920 |
-
template<class T>
|
| 921 |
-
constexpr bool has_single_bit(T x) noexcept;
|
| 922 |
-
```
|
| 923 |
-
|
| 924 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 925 |
-
|
| 926 |
-
*Returns:* `true` if `x` is an integral power of two; `false` otherwise.
|
| 927 |
-
|
| 928 |
-
``` cpp
|
| 929 |
-
template<class T>
|
| 930 |
-
constexpr T bit_ceil(T x);
|
| 931 |
-
```
|
| 932 |
-
|
| 933 |
-
Let N be the smallest power of 2 greater than or equal to `x`.
|
| 934 |
-
|
| 935 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 936 |
-
|
| 937 |
-
*Preconditions:* N is representable as a value of type `T`.
|
| 938 |
-
|
| 939 |
-
*Returns:* N.
|
| 940 |
-
|
| 941 |
-
*Throws:* Nothing.
|
| 942 |
-
|
| 943 |
-
*Remarks:* A function call expression that violates the precondition in
|
| 944 |
-
the *Preconditions:* element is not a core constant
|
| 945 |
-
expression [[expr.const]].
|
| 946 |
-
|
| 947 |
-
``` cpp
|
| 948 |
-
template<class T>
|
| 949 |
-
constexpr T bit_floor(T x) noexcept;
|
| 950 |
-
```
|
| 951 |
-
|
| 952 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 953 |
-
|
| 954 |
-
*Returns:* If `x == 0`, `0`; otherwise the maximal value `y` such that
|
| 955 |
-
`has_single_bit(y)` is `true` and `y <= x`.
|
| 956 |
-
|
| 957 |
-
``` cpp
|
| 958 |
-
template<class T>
|
| 959 |
-
constexpr T bit_width(T x) noexcept;
|
| 960 |
-
```
|
| 961 |
-
|
| 962 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 963 |
-
|
| 964 |
-
*Returns:* If `x == 0`, `0`; otherwise one plus the base-2 logarithm of
|
| 965 |
-
`x`, with any fractional part discarded.
|
| 966 |
-
|
| 967 |
-
### Rotating <a id="bit.rotate">[[bit.rotate]]</a>
|
| 968 |
-
|
| 969 |
-
In the following descriptions, let `N` denote
|
| 970 |
-
`numeric_limits<T>::digits`.
|
| 971 |
-
|
| 972 |
-
``` cpp
|
| 973 |
-
template<class T>
|
| 974 |
-
[[nodiscard]] constexpr T rotl(T x, int s) noexcept;
|
| 975 |
-
```
|
| 976 |
-
|
| 977 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 978 |
-
|
| 979 |
-
Let `r` be `s % N`.
|
| 980 |
-
|
| 981 |
-
*Returns:* If `r` is `0`, `x`; if `r` is positive,
|
| 982 |
-
`(x << r) | (x >> (N - r))`; if `r` is negative, `rotr(x, -r)`.
|
| 983 |
-
|
| 984 |
-
``` cpp
|
| 985 |
-
template<class T>
|
| 986 |
-
[[nodiscard]] constexpr T rotr(T x, int s) noexcept;
|
| 987 |
-
```
|
| 988 |
-
|
| 989 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 990 |
-
|
| 991 |
-
Let `r` be `s % N`.
|
| 992 |
-
|
| 993 |
-
*Returns:* If `r` is `0`, `x`; if `r` is positive,
|
| 994 |
-
`(x >> r) | (x << (N - r))`; if `r` is negative, `rotl(x, -r)`.
|
| 995 |
-
|
| 996 |
-
### Counting <a id="bit.count">[[bit.count]]</a>
|
| 997 |
-
|
| 998 |
-
In the following descriptions, let `N` denote
|
| 999 |
-
`numeric_limits<T>::digits`.
|
| 1000 |
-
|
| 1001 |
-
``` cpp
|
| 1002 |
-
template<class T>
|
| 1003 |
-
constexpr int countl_zero(T x) noexcept;
|
| 1004 |
-
```
|
| 1005 |
-
|
| 1006 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 1007 |
-
|
| 1008 |
-
*Returns:* The number of consecutive `0` bits in the value of `x`,
|
| 1009 |
-
starting from the most significant bit.
|
| 1010 |
-
|
| 1011 |
-
[*Note 1*: Returns `N` if `x == 0`. — *end note*]
|
| 1012 |
-
|
| 1013 |
-
``` cpp
|
| 1014 |
-
template<class T>
|
| 1015 |
-
constexpr int countl_one(T x) noexcept;
|
| 1016 |
-
```
|
| 1017 |
-
|
| 1018 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 1019 |
-
|
| 1020 |
-
*Returns:* The number of consecutive `1` bits in the value of `x`,
|
| 1021 |
-
starting from the most significant bit.
|
| 1022 |
-
|
| 1023 |
-
[*Note 2*: Returns `N` if
|
| 1024 |
-
`x == numeric_limits<T>::max()`. — *end note*]
|
| 1025 |
-
|
| 1026 |
-
``` cpp
|
| 1027 |
-
template<class T>
|
| 1028 |
-
constexpr int countr_zero(T x) noexcept;
|
| 1029 |
-
```
|
| 1030 |
-
|
| 1031 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 1032 |
-
|
| 1033 |
-
*Returns:* The number of consecutive `0` bits in the value of `x`,
|
| 1034 |
-
starting from the least significant bit.
|
| 1035 |
-
|
| 1036 |
-
[*Note 3*: Returns `N` if `x == 0`. — *end note*]
|
| 1037 |
-
|
| 1038 |
-
``` cpp
|
| 1039 |
-
template<class T>
|
| 1040 |
-
constexpr int countr_one(T x) noexcept;
|
| 1041 |
-
```
|
| 1042 |
-
|
| 1043 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 1044 |
-
|
| 1045 |
-
*Returns:* The number of consecutive `1` bits in the value of `x`,
|
| 1046 |
-
starting from the least significant bit.
|
| 1047 |
-
|
| 1048 |
-
[*Note 4*: Returns `N` if
|
| 1049 |
-
`x == numeric_limits<T>::max()`. — *end note*]
|
| 1050 |
-
|
| 1051 |
-
``` cpp
|
| 1052 |
-
template<class T>
|
| 1053 |
-
constexpr int popcount(T x) noexcept;
|
| 1054 |
-
```
|
| 1055 |
-
|
| 1056 |
-
*Constraints:* `T` is an unsigned integer type [[basic.fundamental]].
|
| 1057 |
-
|
| 1058 |
-
*Returns:* The number of `1` bits in the value of `x`.
|
| 1059 |
-
|
| 1060 |
-
### Endian <a id="bit.endian">[[bit.endian]]</a>
|
| 1061 |
-
|
| 1062 |
-
Two common methods of byte ordering in multibyte scalar types are
|
| 1063 |
-
big-endian and little-endian in the execution environment. Big-endian is
|
| 1064 |
-
a format for storage of binary data in which the most significant byte
|
| 1065 |
-
is placed first, with the rest in descending order. Little-endian is a
|
| 1066 |
-
format for storage of binary data in which the least significant byte is
|
| 1067 |
-
placed first, with the rest in ascending order. This subclause describes
|
| 1068 |
-
the endianness of the scalar types of the execution environment.
|
| 1069 |
-
|
| 1070 |
-
``` cpp
|
| 1071 |
-
enum class endian {
|
| 1072 |
-
little = see below,
|
| 1073 |
-
big = see below,
|
| 1074 |
-
native = see below
|
| 1075 |
-
};
|
| 1076 |
-
```
|
| 1077 |
-
|
| 1078 |
-
If all scalar types have size 1 byte, then all of `endian::little`,
|
| 1079 |
-
`endian::big`, and `endian::native` have the same value. Otherwise,
|
| 1080 |
-
`endian::little` is not equal to `endian::big`. If all scalar types are
|
| 1081 |
-
big-endian, `endian::native` is equal to `endian::big`. If all scalar
|
| 1082 |
-
types are little-endian, `endian::native` is equal to `endian::little`.
|
| 1083 |
-
Otherwise, `endian::native` is not equal to either `endian::big` or
|
| 1084 |
-
`endian::little`.
|
| 1085 |
-
|
| 1086 |
## Random number generation <a id="rand">[[rand]]</a>
|
| 1087 |
|
| 1088 |
-
|
|
|
|
|
|
|
| 1089 |
numbers.
|
| 1090 |
|
| 1091 |
In addition to a few utilities, four categories of entities are
|
| 1092 |
described: *uniform random bit generators*, *random number engines*,
|
| 1093 |
*random number engine adaptors*, and *random number distributions*.
|
|
@@ -1099,39 +761,39 @@ to templates producing such types when instantiated.
|
|
| 1099 |
binding of any uniform random bit generator object `e` as the argument
|
| 1100 |
to any random number distribution object `d`, thus producing a
|
| 1101 |
zero-argument function object such as given by
|
| 1102 |
`bind(d,e)`. — *end note*]
|
| 1103 |
|
| 1104 |
-
Each of the entities specified
|
| 1105 |
-
|
| 1106 |
-
`
|
| 1107 |
-
|
| 1108 |
|
| 1109 |
- as *boolean* or equivalently as *boolean-valued*, if `T` is `bool`;
|
| 1110 |
- otherwise as *integral* or equivalently as *integer-valued*, if
|
| 1111 |
`numeric_limits<T>::is_integer` is `true`;
|
| 1112 |
- otherwise as *floating-point* or equivalently as *real-valued*.
|
| 1113 |
|
| 1114 |
If integer-valued, an entity may optionally be further characterized as
|
| 1115 |
*signed* or *unsigned*, according to `numeric_limits<T>::is_signed`.
|
| 1116 |
|
| 1117 |
-
Unless otherwise specified, all descriptions of calculations in
|
| 1118 |
-
|
| 1119 |
|
| 1120 |
-
Throughout
|
| 1121 |
-
|
| 1122 |
|
| 1123 |
- the operator \rightshift denotes a bitwise right shift with
|
| 1124 |
zero-valued bits appearing in the high bits of the result, and
|
| 1125 |
- the operator denotes a bitwise left shift with zero-valued bits
|
| 1126 |
appearing in the low bits of the result, and whose result is always
|
| 1127 |
taken modulo 2ʷ.
|
| 1128 |
|
| 1129 |
### Header `<random>` synopsis <a id="rand.synopsis">[[rand.synopsis]]</a>
|
| 1130 |
|
| 1131 |
``` cpp
|
| 1132 |
-
#include <initializer_list>
|
| 1133 |
|
| 1134 |
namespace std {
|
| 1135 |
// [rand.req.urng], uniform random bit generator requirements
|
| 1136 |
template<class G>
|
| 1137 |
concept uniform_random_bit_generator = see below;
|
|
@@ -1320,17 +982,18 @@ shown in [[rand.req.seedseq]] are valid and have the indicated
|
|
| 1320 |
semantics, and if `S` also meets all other requirements of this
|
| 1321 |
subclause [[rand.req.seedseq]]. In that Table and throughout this
|
| 1322 |
subclause:
|
| 1323 |
|
| 1324 |
- `T` is the type named by `S`’s associated `result_type`;
|
| 1325 |
-
- `q` is a value of `S` and `r` is a
|
|
|
|
| 1326 |
- `ib` and `ie` are input iterators with an unsigned integer
|
| 1327 |
`value_type` of at least 32 bits;
|
| 1328 |
- `rb` and `re` are mutable random access iterators with an unsigned
|
| 1329 |
integer `value_type` of at least 32 bits;
|
| 1330 |
- `ob` is an output iterator; and
|
| 1331 |
-
- `il` is a value of `initializer_list<T>`.
|
| 1332 |
|
| 1333 |
#### Uniform random bit generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
|
| 1334 |
|
| 1335 |
A *uniform random bit generator* `g` of type `G` is a function object
|
| 1336 |
returning unsigned integer values such that each value in the range of
|
|
@@ -1391,22 +1054,22 @@ and have the indicated semantics, and if `E` also meets all other
|
|
| 1391 |
requirements of this subclause [[rand.req.eng]]. In that Table and
|
| 1392 |
throughout this subclause:
|
| 1393 |
|
| 1394 |
- `T` is the type named by `E`’s associated `result_type`;
|
| 1395 |
- `e` is a value of `E`, `v` is an lvalue of `E`, `x` and `y` are
|
| 1396 |
-
(possibly
|
| 1397 |
- `s` is a value of `T`;
|
| 1398 |
- `q` is an lvalue meeting the requirements of a seed sequence
|
| 1399 |
[[rand.req.seedseq]];
|
| 1400 |
- `z` is a value of type `unsigned long long`;
|
| 1401 |
- `os` is an lvalue of the type of some class template specialization
|
| 1402 |
`basic_ostream<charT,` `traits>`; and
|
| 1403 |
- `is` is an lvalue of the type of some class template specialization
|
| 1404 |
`basic_istream<charT,` `traits>`;
|
| 1405 |
|
| 1406 |
where `charT` and `traits` are constrained according to [[strings]] and
|
| 1407 |
-
[[input.output]].
|
| 1408 |
|
| 1409 |
`E` shall meet the *Cpp17CopyConstructible* (
|
| 1410 |
[[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
|
| 1411 |
[[cpp17.copyassignable]]) requirements. These operations shall each be
|
| 1412 |
of complexity no worse than 𝑂(\text{size of state}).
|
|
@@ -1502,17 +1165,17 @@ indicated semantics, and if `D` and its associated types also meet all
|
|
| 1502 |
other requirements of this subclause [[rand.req.dist]]. In that Table
|
| 1503 |
and throughout this subclause,
|
| 1504 |
|
| 1505 |
- `T` is the type named by `D`’s associated `result_type`;
|
| 1506 |
- `P` is the type named by `D`’s associated `param_type`;
|
| 1507 |
-
- `d` is a value of `D`, and `x` and `y` are (possibly
|
| 1508 |
-
|
| 1509 |
- `glb` and `lub` are values of `T` respectively corresponding to the
|
| 1510 |
greatest lower bound and the least upper bound on the values
|
| 1511 |
potentially returned by `d`’s `operator()`, as determined by the
|
| 1512 |
current values of `d`’s parameters;
|
| 1513 |
-
- `p` is a (possibly
|
| 1514 |
- `g`, `g1`, and `g2` are lvalues of a type meeting the requirements of
|
| 1515 |
a uniform random bit generator [[rand.req.urng]];
|
| 1516 |
- `os` is an lvalue of the type of some class template specialization
|
| 1517 |
`basic_ostream<charT,` `traits>`; and
|
| 1518 |
- `is` is an lvalue of the type of some class template specialization
|
|
@@ -1525,11 +1188,11 @@ where `charT` and `traits` are constrained according to [[strings]] and
|
|
| 1525 |
[[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
|
| 1526 |
[[cpp17.copyassignable]]) requirements.
|
| 1527 |
|
| 1528 |
The sequence of numbers produced by repeated invocations of `d(g)` shall
|
| 1529 |
be independent of any invocation of `os << d` or of any `const` member
|
| 1530 |
-
function of `D` between any of the invocations `d(g)`.
|
| 1531 |
|
| 1532 |
If a textual representation is written using `os << x` and that
|
| 1533 |
representation is restored into the same or a different object `y` of
|
| 1534 |
the same type using `is >> y`, repeated invocations of `y(g)` shall
|
| 1535 |
produce the same sequence of numbers as would repeated invocations of
|
|
@@ -1559,40 +1222,39 @@ the identical name, type, and semantics.
|
|
| 1559 |
using distribution_type = D;
|
| 1560 |
```
|
| 1561 |
|
| 1562 |
### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
|
| 1563 |
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
[[rand.
|
|
|
|
| 1567 |
|
| 1568 |
Except where specified otherwise, the complexity of each function
|
| 1569 |
-
specified in
|
| 1570 |
|
| 1571 |
-
Except where specified otherwise, no function described in
|
| 1572 |
-
|
| 1573 |
|
| 1574 |
-
Every function described in
|
| 1575 |
-
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
|
| 1579 |
-
Descriptions are provided in
|
| 1580 |
-
|
| 1581 |
-
|
| 1582 |
-
|
| 1583 |
-
|
| 1584 |
-
operators are not shown in the synopses.
|
| 1585 |
|
| 1586 |
-
Each template specified in
|
| 1587 |
-
|
| 1588 |
parameter(s), to hold. A program instantiating any of these templates is
|
| 1589 |
ill-formed if any such required relationship fails to hold.
|
| 1590 |
|
| 1591 |
For every random number engine and for every random number engine
|
| 1592 |
-
adaptor `X` defined in
|
| 1593 |
-
[[rand.adapt]]:
|
| 1594 |
|
| 1595 |
- if the constructor
|
| 1596 |
``` cpp
|
| 1597 |
template<class Sseq> explicit X(Sseq& q);
|
| 1598 |
```
|
|
@@ -1620,10 +1282,11 @@ object `x` is of size 1 and consists of a single integer. The transition
|
|
| 1620 |
algorithm is a modular linear function of the form
|
| 1621 |
TA(xᵢ) = (a ⋅ xᵢ + c) mod m; the generation algorithm is
|
| 1622 |
GA(xᵢ) = xᵢ₊₁.
|
| 1623 |
|
| 1624 |
``` cpp
|
|
|
|
| 1625 |
template<class UIntType, UIntType a, UIntType c, UIntType m>
|
| 1626 |
class linear_congruential_engine {
|
| 1627 |
public:
|
| 1628 |
// types
|
| 1629 |
using result_type = UIntType;
|
|
@@ -1641,14 +1304,27 @@ template<class UIntType, UIntType a, UIntType c, UIntType m>
|
|
| 1641 |
explicit linear_congruential_engine(result_type s);
|
| 1642 |
template<class Sseq> explicit linear_congruential_engine(Sseq& q);
|
| 1643 |
void seed(result_type s = default_seed);
|
| 1644 |
template<class Sseq> void seed(Sseq& q);
|
| 1645 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1646 |
// generating functions
|
| 1647 |
result_type operator()();
|
| 1648 |
void discard(unsigned long long z);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1649 |
};
|
|
|
|
| 1650 |
```
|
| 1651 |
|
| 1652 |
If the template parameter `m` is 0, the modulus m used throughout this
|
| 1653 |
subclause [[rand.eng.lcong]] is `numeric_limits<result_type>::max()`
|
| 1654 |
plus 1.
|
|
@@ -1679,15 +1355,16 @@ $S = \left(\sum_{j = 0}^{k - 1} a_{j + 3} \cdot 2^{32j} \right) \bmod m$.
|
|
| 1679 |
If c mod m is 0 and S is 0, sets the engine’s state to 1, else sets
|
| 1680 |
the engine’s state to S.
|
| 1681 |
|
| 1682 |
#### Class template `mersenne_twister_engine` <a id="rand.eng.mers">[[rand.eng.mers]]</a>
|
| 1683 |
|
| 1684 |
-
A `mersenne_twister_engine` random number engine[^
|
| 1685 |
-
|
| 1686 |
-
|
| 1687 |
-
|
| 1688 |
-
|
|
|
|
| 1689 |
|
| 1690 |
The transition algorithm employs a twisted generalized feedback shift
|
| 1691 |
register defined by shift values n and m, a twist value r, and a
|
| 1692 |
conditional xor-mask a. To improve the uniformity of the result, the
|
| 1693 |
bits of the raw shift register are additionally *tempered* (i.e.,
|
|
@@ -1711,10 +1388,11 @@ z₁, z₂, z₃, z₄ as follows, then delivers z₄ as its result:
|
|
| 1711 |
- Let $z_2 = z_1 \xor \bigl( (z_1 \leftshift{w} s) \bitand b \bigr)$.
|
| 1712 |
- Let $z_3 = z_2 \xor \bigl( (z_2 \leftshift{w} t) \bitand c \bigr)$.
|
| 1713 |
- Let $z_4 = z_3 \xor ( z_3 \rightshift \ell )$.
|
| 1714 |
|
| 1715 |
``` cpp
|
|
|
|
| 1716 |
template<class UIntType, size_t w, size_t n, size_t m, size_t r,
|
| 1717 |
UIntType a, size_t u, UIntType d, size_t s,
|
| 1718 |
UIntType b, size_t t,
|
| 1719 |
UIntType c, size_t l, UIntType f>
|
| 1720 |
class mersenne_twister_engine {
|
|
@@ -1745,14 +1423,26 @@ template<class UIntType, size_t w, size_t n, size_t m, size_t r,
|
|
| 1745 |
explicit mersenne_twister_engine(result_type value);
|
| 1746 |
template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
|
| 1747 |
void seed(result_type value = default_seed);
|
| 1748 |
template<class Sseq> void seed(Sseq& q);
|
| 1749 |
|
|
|
|
|
|
|
|
|
|
| 1750 |
// generating functions
|
| 1751 |
result_type operator()();
|
| 1752 |
void discard(unsigned long long z);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1753 |
};
|
|
|
|
| 1754 |
```
|
| 1755 |
|
| 1756 |
The following relations shall hold: `0 < m`, `m <= n`, `2u < w`,
|
| 1757 |
`r <= w`, `u <= w`, `s <= w`, `t <= w`, `l <= w`,
|
| 1758 |
`w <= numeric_limits<UIntType>::digits`, `a <= (1u<<w) - 1u`,
|
|
@@ -1810,10 +1500,11 @@ and a = b - (b - 1) / m. — *end note*]
|
|
| 1810 |
|
| 1811 |
The generation algorithm is given by GA(xᵢ) = y, where y is the value
|
| 1812 |
produced as a result of advancing the engine’s state as described above.
|
| 1813 |
|
| 1814 |
``` cpp
|
|
|
|
| 1815 |
template<class UIntType, size_t w, size_t s, size_t r>
|
| 1816 |
class subtract_with_carry_engine {
|
| 1817 |
public:
|
| 1818 |
// types
|
| 1819 |
using result_type = UIntType;
|
|
@@ -1831,14 +1522,27 @@ template<class UIntType, size_t w, size_t s, size_t r>
|
|
| 1831 |
explicit subtract_with_carry_engine(result_type value);
|
| 1832 |
template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
|
| 1833 |
void seed(result_type value = default_seed);
|
| 1834 |
template<class Sseq> void seed(Sseq& q);
|
| 1835 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1836 |
// generating functions
|
| 1837 |
result_type operator()();
|
| 1838 |
void discard(unsigned long long z);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1839 |
};
|
|
|
|
| 1840 |
```
|
| 1841 |
|
| 1842 |
The following relations shall hold: `0u < s`, `s < r`, `0 < w`, and
|
| 1843 |
`w <= numeric_limits<UIntType>::digits`.
|
| 1844 |
|
|
@@ -1859,11 +1563,11 @@ To set the values Xₖ, first construct `e`, a
|
|
| 1859 |
linear_congruential_engine<result_type,
|
| 1860 |
40014u,0u,2147483563u> e(value == 0u ? default_seed : value);
|
| 1861 |
```
|
| 1862 |
|
| 1863 |
Then, to set each Xₖ, obtain new values z₀, …, zₙ₋₁ from n = ⌈ w/32 ⌉
|
| 1864 |
-
successive invocations of `e`
|
| 1865 |
$\left( \sum_{j=0}^{n-1} z_j \cdot 2^{32j}\right) \bmod m$.
|
| 1866 |
|
| 1867 |
*Complexity:* Exactly n ⋅ `r` invocations of `e`.
|
| 1868 |
|
| 1869 |
``` cpp
|
|
@@ -1923,10 +1627,11 @@ state eⱼ to eⱼ₊₁.
|
|
| 1923 |
|
| 1924 |
The generation algorithm yields the value returned by the last
|
| 1925 |
invocation of `e()` while advancing `e`’s state as described above.
|
| 1926 |
|
| 1927 |
``` cpp
|
|
|
|
| 1928 |
template<class Engine, size_t p, size_t r>
|
| 1929 |
class discard_block_engine {
|
| 1930 |
public:
|
| 1931 |
// types
|
| 1932 |
using result_type = typename Engine::result_type;
|
|
@@ -1945,21 +1650,33 @@ template<class Engine, size_t p, size_t r>
|
|
| 1945 |
template<class Sseq> explicit discard_block_engine(Sseq& q);
|
| 1946 |
void seed();
|
| 1947 |
void seed(result_type s);
|
| 1948 |
template<class Sseq> void seed(Sseq& q);
|
| 1949 |
|
|
|
|
|
|
|
|
|
|
| 1950 |
// generating functions
|
| 1951 |
result_type operator()();
|
| 1952 |
void discard(unsigned long long z);
|
| 1953 |
|
| 1954 |
// property functions
|
| 1955 |
-
const Engine& base() const noexcept { return e; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1956 |
|
| 1957 |
private:
|
| 1958 |
Engine e; // exposition only
|
| 1959 |
-
|
| 1960 |
};
|
|
|
|
| 1961 |
```
|
| 1962 |
|
| 1963 |
The following relations shall hold: `0 < r` and `r <= p`.
|
| 1964 |
|
| 1965 |
The textual representation consists of the textual representation of `e`
|
|
@@ -2029,16 +1746,27 @@ template<class Engine, size_t w, class UIntType>
|
|
| 2029 |
template<class Sseq> explicit independent_bits_engine(Sseq& q);
|
| 2030 |
void seed();
|
| 2031 |
void seed(result_type s);
|
| 2032 |
template<class Sseq> void seed(Sseq& q);
|
| 2033 |
|
|
|
|
|
|
|
|
|
|
| 2034 |
// generating functions
|
| 2035 |
result_type operator()();
|
| 2036 |
void discard(unsigned long long z);
|
| 2037 |
|
| 2038 |
// property functions
|
| 2039 |
-
const Engine& base() const noexcept { return e; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2040 |
|
| 2041 |
private:
|
| 2042 |
Engine e; // exposition only
|
| 2043 |
};
|
| 2044 |
```
|
|
@@ -2069,10 +1797,11 @@ transition is performed as follows:
|
|
| 2069 |
|
| 2070 |
The generation algorithm yields the last value of `Y` produced while
|
| 2071 |
advancing `e`’s state as described above.
|
| 2072 |
|
| 2073 |
``` cpp
|
|
|
|
| 2074 |
template<class Engine, size_t k>
|
| 2075 |
class shuffle_order_engine {
|
| 2076 |
public:
|
| 2077 |
// types
|
| 2078 |
using result_type = typename Engine::result_type;
|
|
@@ -2090,22 +1819,34 @@ template<class Engine, size_t k>
|
|
| 2090 |
template<class Sseq> explicit shuffle_order_engine(Sseq& q);
|
| 2091 |
void seed();
|
| 2092 |
void seed(result_type s);
|
| 2093 |
template<class Sseq> void seed(Sseq& q);
|
| 2094 |
|
|
|
|
|
|
|
|
|
|
| 2095 |
// generating functions
|
| 2096 |
result_type operator()();
|
| 2097 |
void discard(unsigned long long z);
|
| 2098 |
|
| 2099 |
// property functions
|
| 2100 |
-
const Engine& base() const noexcept { return e; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2101 |
|
| 2102 |
private:
|
| 2103 |
Engine e; // exposition only
|
| 2104 |
result_type V[k]; // exposition only
|
| 2105 |
result_type Y; // exposition only
|
| 2106 |
};
|
|
|
|
| 2107 |
```
|
| 2108 |
|
| 2109 |
The following relation shall hold: `0 < k`.
|
| 2110 |
|
| 2111 |
The textual representation consists of the textual representation of
|
|
@@ -2204,14 +1945,14 @@ using default_random_engine = implementation-defined;
|
|
| 2204 |
```
|
| 2205 |
|
| 2206 |
*Remarks:* The choice of engine type named by this `typedef` is
|
| 2207 |
*implementation-defined*.
|
| 2208 |
|
| 2209 |
-
[*Note 1*: The implementation
|
| 2210 |
performance, size, quality, or any combination of such factors, so as to
|
| 2211 |
provide at least acceptable engine behavior for relatively casual,
|
| 2212 |
-
inexpert, and/or lightweight use. Because different implementations
|
| 2213 |
select different underlying engine types, code that uses this `typedef`
|
| 2214 |
need not generate identical sequences across
|
| 2215 |
implementations. — *end note*]
|
| 2216 |
|
| 2217 |
### Class `random_device` <a id="rand.device">[[rand.device]]</a>
|
|
@@ -2221,10 +1962,11 @@ random numbers.
|
|
| 2221 |
|
| 2222 |
If implementation limitations prevent generating nondeterministic random
|
| 2223 |
numbers, the implementation may employ a random number engine.
|
| 2224 |
|
| 2225 |
``` cpp
|
|
|
|
| 2226 |
class random_device {
|
| 2227 |
public:
|
| 2228 |
// types
|
| 2229 |
using result_type = unsigned int;
|
| 2230 |
|
|
@@ -2244,53 +1986,57 @@ public:
|
|
| 2244 |
|
| 2245 |
// no copy functions
|
| 2246 |
random_device(const random_device&) = delete;
|
| 2247 |
void operator=(const random_device&) = delete;
|
| 2248 |
};
|
|
|
|
| 2249 |
```
|
| 2250 |
|
| 2251 |
``` cpp
|
| 2252 |
explicit random_device(const string& token);
|
| 2253 |
```
|
| 2254 |
|
|
|
|
|
|
|
|
|
|
| 2255 |
*Remarks:* The semantics of the `token` parameter and the token value
|
| 2256 |
-
used by the default constructor are *implementation-defined*.
|
| 2257 |
-
|
| 2258 |
-
*Throws:* A value of an *implementation-defined* type derived from
|
| 2259 |
-
`exception` if the `random_device` could not be initialized.
|
| 2260 |
|
| 2261 |
``` cpp
|
| 2262 |
double entropy() const noexcept;
|
| 2263 |
```
|
| 2264 |
|
| 2265 |
*Returns:* If the implementation employs a random number engine, returns
|
| 2266 |
-
0.0. Otherwise, returns an entropy estimate[^
|
| 2267 |
-
|
|
|
|
|
|
|
| 2268 |
|
| 2269 |
``` cpp
|
| 2270 |
result_type operator()();
|
| 2271 |
```
|
| 2272 |
|
| 2273 |
*Returns:* A nondeterministic random value, uniformly distributed
|
| 2274 |
between `min()` and `max()` (inclusive). It is *implementation-defined*
|
| 2275 |
how these values are generated.
|
| 2276 |
|
| 2277 |
*Throws:* A value of an *implementation-defined* type derived from
|
| 2278 |
-
`exception` if a random number
|
| 2279 |
|
| 2280 |
### Utilities <a id="rand.util">[[rand.util]]</a>
|
| 2281 |
|
| 2282 |
#### Class `seed_seq` <a id="rand.util.seedseq">[[rand.util.seedseq]]</a>
|
| 2283 |
|
| 2284 |
``` cpp
|
|
|
|
| 2285 |
class seed_seq {
|
| 2286 |
public:
|
| 2287 |
// types
|
| 2288 |
using result_type = uint_least32_t;
|
| 2289 |
|
| 2290 |
// constructors
|
| 2291 |
-
|
| 2292 |
template<class T>
|
| 2293 |
seed_seq(initializer_list<T> il);
|
| 2294 |
template<class InputIterator>
|
| 2295 |
seed_seq(InputIterator begin, InputIterator end);
|
| 2296 |
|
|
@@ -2308,26 +2054,25 @@ public:
|
|
| 2308 |
void operator=(const seed_seq&) = delete;
|
| 2309 |
|
| 2310 |
private:
|
| 2311 |
vector<result_type> v; // exposition only
|
| 2312 |
};
|
|
|
|
| 2313 |
```
|
| 2314 |
|
| 2315 |
``` cpp
|
| 2316 |
-
seed_seq();
|
| 2317 |
```
|
| 2318 |
|
| 2319 |
*Ensures:* `v.empty()` is `true`.
|
| 2320 |
|
| 2321 |
-
*Throws:* Nothing.
|
| 2322 |
-
|
| 2323 |
``` cpp
|
| 2324 |
template<class T>
|
| 2325 |
seed_seq(initializer_list<T> il);
|
| 2326 |
```
|
| 2327 |
|
| 2328 |
-
*
|
| 2329 |
|
| 2330 |
*Effects:* Same as `seed_seq(il.begin(), il.end())`.
|
| 2331 |
|
| 2332 |
``` cpp
|
| 2333 |
template<class InputIterator>
|
|
@@ -2443,14 +2188,10 @@ copy(v.begin(), v.end(), dest);
|
|
| 2443 |
``` cpp
|
| 2444 |
template<class RealType, size_t bits, class URBG>
|
| 2445 |
RealType generate_canonical(URBG& g);
|
| 2446 |
```
|
| 2447 |
|
| 2448 |
-
*Complexity:* Exactly k = max(1, ⌈ b / log₂ R ⌉) invocations of `g`,
|
| 2449 |
-
where b[^5] is the lesser of `numeric_limits<RealType>::digits` and
|
| 2450 |
-
`bits`, and R is the value of `g.max()` - `g.min()` + 1.
|
| 2451 |
-
|
| 2452 |
*Effects:* Invokes `g()` k times to obtain values g₀, …, gₖ₋₁,
|
| 2453 |
respectively. Calculates a quantity
|
| 2454 |
$$S = \sum_{i=0}^{k-1} (g_i - \texttt{g.min()})
|
| 2455 |
\cdot R^i$$ using arithmetic of type `RealType`.
|
| 2456 |
|
|
@@ -2458,10 +2199,16 @@ $$S = \sum_{i=0}^{k-1} (g_i - \texttt{g.min()})
|
|
| 2458 |
|
| 2459 |
[*Note 1*: 0 ≤ S / Rᵏ < 1. — *end note*]
|
| 2460 |
|
| 2461 |
*Throws:* What and when `g` throws.
|
| 2462 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2463 |
[*Note 2*: If the values gᵢ produced by `g` are uniformly distributed,
|
| 2464 |
the instantiation’s results are distributed as uniformly as possible.
|
| 2465 |
Obtaining a value in this way can be a useful step in the process of
|
| 2466 |
transforming a value generated by a uniform random bit generator into a
|
| 2467 |
value that can be delivered by a random number
|
|
@@ -2496,10 +2243,11 @@ outside its stated domain.
|
|
| 2496 |
A `uniform_int_distribution` random number distribution produces random
|
| 2497 |
integers i, a ≤ i ≤ b, distributed according to the constant discrete
|
| 2498 |
probability function $$P(i\,|\,a,b) = 1 / (b - a + 1) \text{ .}$$
|
| 2499 |
|
| 2500 |
``` cpp
|
|
|
|
| 2501 |
template<class IntType = int>
|
| 2502 |
class uniform_int_distribution {
|
| 2503 |
public:
|
| 2504 |
// types
|
| 2505 |
using result_type = IntType;
|
|
@@ -2509,10 +2257,13 @@ template<class IntType = int>
|
|
| 2509 |
uniform_int_distribution() : uniform_int_distribution(0) {}
|
| 2510 |
explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
|
| 2511 |
explicit uniform_int_distribution(const param_type& parm);
|
| 2512 |
void reset();
|
| 2513 |
|
|
|
|
|
|
|
|
|
|
| 2514 |
// generating functions
|
| 2515 |
template<class URBG>
|
| 2516 |
result_type operator()(URBG& g);
|
| 2517 |
template<class URBG>
|
| 2518 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2522,11 +2273,20 @@ template<class IntType = int>
|
|
| 2522 |
result_type b() const;
|
| 2523 |
param_type param() const;
|
| 2524 |
void param(const param_type& parm);
|
| 2525 |
result_type min() const;
|
| 2526 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2527 |
};
|
|
|
|
| 2528 |
```
|
| 2529 |
|
| 2530 |
``` cpp
|
| 2531 |
explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
|
| 2532 |
```
|
|
@@ -2558,10 +2318,11 @@ density function $$p(x\,|\,a,b) = 1 / (b - a) \text{ .}$$
|
|
| 2558 |
|
| 2559 |
[*Note 1*: This implies that p(x | a,b) is undefined when
|
| 2560 |
`a == b`. — *end note*]
|
| 2561 |
|
| 2562 |
``` cpp
|
|
|
|
| 2563 |
template<class RealType = double>
|
| 2564 |
class uniform_real_distribution {
|
| 2565 |
public:
|
| 2566 |
// types
|
| 2567 |
using result_type = RealType;
|
|
@@ -2571,10 +2332,14 @@ template<class RealType = double>
|
|
| 2571 |
uniform_real_distribution() : uniform_real_distribution(0.0) {}
|
| 2572 |
explicit uniform_real_distribution(RealType a, RealType b = 1.0);
|
| 2573 |
explicit uniform_real_distribution(const param_type& parm);
|
| 2574 |
void reset();
|
| 2575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2576 |
// generating functions
|
| 2577 |
template<class URBG>
|
| 2578 |
result_type operator()(URBG& g);
|
| 2579 |
template<class URBG>
|
| 2580 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2584,11 +2349,20 @@ template<class RealType = double>
|
|
| 2584 |
result_type b() const;
|
| 2585 |
param_type param() const;
|
| 2586 |
void param(const param_type& parm);
|
| 2587 |
result_type min() const;
|
| 2588 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2589 |
};
|
|
|
|
| 2590 |
```
|
| 2591 |
|
| 2592 |
``` cpp
|
| 2593 |
explicit uniform_real_distribution(RealType a, RealType b = 1.0);
|
| 2594 |
```
|
|
@@ -2623,10 +2397,11 @@ $$P(b\,|\,p) = \left\{ \begin{array}{ll}
|
|
| 2623 |
p & \text{ if $b = \tcode{true}$, or} \\
|
| 2624 |
1 - p & \text{ if $b = \tcode{false}$.}
|
| 2625 |
\end{array}\right.$$
|
| 2626 |
|
| 2627 |
``` cpp
|
|
|
|
| 2628 |
class bernoulli_distribution {
|
| 2629 |
public:
|
| 2630 |
// types
|
| 2631 |
using result_type = bool;
|
| 2632 |
using param_type = unspecified;
|
|
@@ -2635,10 +2410,13 @@ public:
|
|
| 2635 |
bernoulli_distribution() : bernoulli_distribution(0.5) {}
|
| 2636 |
explicit bernoulli_distribution(double p);
|
| 2637 |
explicit bernoulli_distribution(const param_type& parm);
|
| 2638 |
void reset();
|
| 2639 |
|
|
|
|
|
|
|
|
|
|
| 2640 |
// generating functions
|
| 2641 |
template<class URBG>
|
| 2642 |
result_type operator()(URBG& g);
|
| 2643 |
template<class URBG>
|
| 2644 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2647,11 +2425,20 @@ public:
|
|
| 2647 |
double p() const;
|
| 2648 |
param_type param() const;
|
| 2649 |
void param(const param_type& parm);
|
| 2650 |
result_type min() const;
|
| 2651 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2652 |
};
|
|
|
|
| 2653 |
```
|
| 2654 |
|
| 2655 |
``` cpp
|
| 2656 |
explicit bernoulli_distribution(double p);
|
| 2657 |
```
|
|
@@ -2672,10 +2459,11 @@ constructed.
|
|
| 2672 |
A `binomial_distribution` random number distribution produces integer
|
| 2673 |
values i ≥ 0 distributed according to the discrete probability function
|
| 2674 |
$$P(i\,|\,t,p) = \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i} \text{ .}$$
|
| 2675 |
|
| 2676 |
``` cpp
|
|
|
|
| 2677 |
template<class IntType = int>
|
| 2678 |
class binomial_distribution {
|
| 2679 |
public:
|
| 2680 |
// types
|
| 2681 |
using result_type = IntType;
|
|
@@ -2685,10 +2473,13 @@ template<class IntType = int>
|
|
| 2685 |
binomial_distribution() : binomial_distribution(1) {}
|
| 2686 |
explicit binomial_distribution(IntType t, double p = 0.5);
|
| 2687 |
explicit binomial_distribution(const param_type& parm);
|
| 2688 |
void reset();
|
| 2689 |
|
|
|
|
|
|
|
|
|
|
| 2690 |
// generating functions
|
| 2691 |
template<class URBG>
|
| 2692 |
result_type operator()(URBG& g);
|
| 2693 |
template<class URBG>
|
| 2694 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2698,11 +2489,20 @@ template<class IntType = int>
|
|
| 2698 |
double p() const;
|
| 2699 |
param_type param() const;
|
| 2700 |
void param(const param_type& parm);
|
| 2701 |
result_type min() const;
|
| 2702 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2703 |
};
|
|
|
|
| 2704 |
```
|
| 2705 |
|
| 2706 |
``` cpp
|
| 2707 |
explicit binomial_distribution(IntType t, double p = 0.5);
|
| 2708 |
```
|
|
@@ -2731,10 +2531,11 @@ constructed.
|
|
| 2731 |
A `geometric_distribution` random number distribution produces integer
|
| 2732 |
values i ≥ 0 distributed according to the discrete probability function
|
| 2733 |
$$P(i\,|\,p) = p \cdot (1-p)^{i} \text{ .}$$
|
| 2734 |
|
| 2735 |
``` cpp
|
|
|
|
| 2736 |
template<class IntType = int>
|
| 2737 |
class geometric_distribution {
|
| 2738 |
public:
|
| 2739 |
// types
|
| 2740 |
using result_type = IntType;
|
|
@@ -2744,10 +2545,13 @@ template<class IntType = int>
|
|
| 2744 |
geometric_distribution() : geometric_distribution(0.5) {}
|
| 2745 |
explicit geometric_distribution(double p);
|
| 2746 |
explicit geometric_distribution(const param_type& parm);
|
| 2747 |
void reset();
|
| 2748 |
|
|
|
|
|
|
|
|
|
|
| 2749 |
// generating functions
|
| 2750 |
template<class URBG>
|
| 2751 |
result_type operator()(URBG& g);
|
| 2752 |
template<class URBG>
|
| 2753 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2756,11 +2560,20 @@ template<class IntType = int>
|
|
| 2756 |
double p() const;
|
| 2757 |
param_type param() const;
|
| 2758 |
void param(const param_type& parm);
|
| 2759 |
result_type min() const;
|
| 2760 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2761 |
};
|
|
|
|
| 2762 |
```
|
| 2763 |
|
| 2764 |
``` cpp
|
| 2765 |
explicit geometric_distribution(double p);
|
| 2766 |
```
|
|
@@ -2785,10 +2598,11 @@ $$P(i\,|\,k,p) = \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i \text{ .}$$
|
|
| 2785 |
|
| 2786 |
[*Note 1*: This implies that P(i | k,p) is undefined when
|
| 2787 |
`p == 1`. — *end note*]
|
| 2788 |
|
| 2789 |
``` cpp
|
|
|
|
| 2790 |
template<class IntType = int>
|
| 2791 |
class negative_binomial_distribution {
|
| 2792 |
public:
|
| 2793 |
// types
|
| 2794 |
using result_type = IntType;
|
|
@@ -2798,10 +2612,14 @@ template<class IntType = int>
|
|
| 2798 |
negative_binomial_distribution() : negative_binomial_distribution(1) {}
|
| 2799 |
explicit negative_binomial_distribution(IntType k, double p = 0.5);
|
| 2800 |
explicit negative_binomial_distribution(const param_type& parm);
|
| 2801 |
void reset();
|
| 2802 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2803 |
// generating functions
|
| 2804 |
template<class URBG>
|
| 2805 |
result_type operator()(URBG& g);
|
| 2806 |
template<class URBG>
|
| 2807 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2811,11 +2629,20 @@ template<class IntType = int>
|
|
| 2811 |
double p() const;
|
| 2812 |
param_type param() const;
|
| 2813 |
void param(const param_type& parm);
|
| 2814 |
result_type min() const;
|
| 2815 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2816 |
};
|
|
|
|
| 2817 |
```
|
| 2818 |
|
| 2819 |
``` cpp
|
| 2820 |
explicit negative_binomial_distribution(IntType k, double p = 0.5);
|
| 2821 |
```
|
|
@@ -2861,10 +2688,13 @@ template<class IntType = int>
|
|
| 2861 |
poisson_distribution() : poisson_distribution(1.0) {}
|
| 2862 |
explicit poisson_distribution(double mean);
|
| 2863 |
explicit poisson_distribution(const param_type& parm);
|
| 2864 |
void reset();
|
| 2865 |
|
|
|
|
|
|
|
|
|
|
| 2866 |
// generating functions
|
| 2867 |
template<class URBG>
|
| 2868 |
result_type operator()(URBG& g);
|
| 2869 |
template<class URBG>
|
| 2870 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2873,10 +2703,18 @@ template<class IntType = int>
|
|
| 2873 |
double mean() const;
|
| 2874 |
param_type param() const;
|
| 2875 |
void param(const param_type& parm);
|
| 2876 |
result_type min() const;
|
| 2877 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2878 |
};
|
| 2879 |
```
|
| 2880 |
|
| 2881 |
``` cpp
|
| 2882 |
explicit poisson_distribution(double mean);
|
|
@@ -2898,10 +2736,11 @@ constructed.
|
|
| 2898 |
An `exponential_distribution` random number distribution produces random
|
| 2899 |
numbers x > 0 distributed according to the probability density function
|
| 2900 |
$$p(x\,|\,\lambda) = \lambda e^{-\lambda x} \text{ .}$$
|
| 2901 |
|
| 2902 |
``` cpp
|
|
|
|
| 2903 |
template<class RealType = double>
|
| 2904 |
class exponential_distribution {
|
| 2905 |
public:
|
| 2906 |
// types
|
| 2907 |
using result_type = RealType;
|
|
@@ -2911,10 +2750,13 @@ template<class RealType = double>
|
|
| 2911 |
exponential_distribution() : exponential_distribution(1.0) {}
|
| 2912 |
explicit exponential_distribution(RealType lambda);
|
| 2913 |
explicit exponential_distribution(const param_type& parm);
|
| 2914 |
void reset();
|
| 2915 |
|
|
|
|
|
|
|
|
|
|
| 2916 |
// generating functions
|
| 2917 |
template<class URBG>
|
| 2918 |
result_type operator()(URBG& g);
|
| 2919 |
template<class URBG>
|
| 2920 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2923,11 +2765,20 @@ template<class RealType = double>
|
|
| 2923 |
RealType lambda() const;
|
| 2924 |
param_type param() const;
|
| 2925 |
void param(const param_type& parm);
|
| 2926 |
result_type min() const;
|
| 2927 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2928 |
};
|
|
|
|
| 2929 |
```
|
| 2930 |
|
| 2931 |
``` cpp
|
| 2932 |
explicit exponential_distribution(RealType lambda);
|
| 2933 |
```
|
|
@@ -2950,10 +2801,11 @@ numbers x > 0 distributed according to the probability density function
|
|
| 2950 |
$$p(x\,|\,\alpha,\beta) =
|
| 2951 |
\frac{e^{-x/\beta}}{\beta^{\alpha} \cdot \Gamma(\alpha)} \, \cdot \, x^{\, \alpha-1}
|
| 2952 |
\text{ .}$$
|
| 2953 |
|
| 2954 |
``` cpp
|
|
|
|
| 2955 |
template<class RealType = double>
|
| 2956 |
class gamma_distribution {
|
| 2957 |
public:
|
| 2958 |
// types
|
| 2959 |
using result_type = RealType;
|
|
@@ -2963,10 +2815,13 @@ template<class RealType = double>
|
|
| 2963 |
gamma_distribution() : gamma_distribution(1.0) {}
|
| 2964 |
explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
|
| 2965 |
explicit gamma_distribution(const param_type& parm);
|
| 2966 |
void reset();
|
| 2967 |
|
|
|
|
|
|
|
|
|
|
| 2968 |
// generating functions
|
| 2969 |
template<class URBG>
|
| 2970 |
result_type operator()(URBG& g);
|
| 2971 |
template<class URBG>
|
| 2972 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -2976,11 +2831,20 @@ template<class RealType = double>
|
|
| 2976 |
RealType beta() const;
|
| 2977 |
param_type param() const;
|
| 2978 |
void param(const param_type& parm);
|
| 2979 |
result_type min() const;
|
| 2980 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2981 |
};
|
|
|
|
| 2982 |
```
|
| 2983 |
|
| 2984 |
``` cpp
|
| 2985 |
explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
|
| 2986 |
```
|
|
@@ -3012,10 +2876,11 @@ $$p(x\,|\,a,b) = \frac{a}{b}
|
|
| 3012 |
\cdot \left(\frac{x}{b}\right)^{a-1}
|
| 3013 |
\cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
|
| 3014 |
\text{ .}$$
|
| 3015 |
|
| 3016 |
``` cpp
|
|
|
|
| 3017 |
template<class RealType = double>
|
| 3018 |
class weibull_distribution {
|
| 3019 |
public:
|
| 3020 |
// types
|
| 3021 |
using result_type = RealType;
|
|
@@ -3025,10 +2890,13 @@ template<class RealType = double>
|
|
| 3025 |
weibull_distribution() : weibull_distribution(1.0) {}
|
| 3026 |
explicit weibull_distribution(RealType a, RealType b = 1.0);
|
| 3027 |
explicit weibull_distribution(const param_type& parm);
|
| 3028 |
void reset();
|
| 3029 |
|
|
|
|
|
|
|
|
|
|
| 3030 |
// generating functions
|
| 3031 |
template<class URBG>
|
| 3032 |
result_type operator()(URBG& g);
|
| 3033 |
template<class URBG>
|
| 3034 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3038,11 +2906,20 @@ template<class RealType = double>
|
|
| 3038 |
RealType b() const;
|
| 3039 |
param_type param() const;
|
| 3040 |
void param(const param_type& parm);
|
| 3041 |
result_type min() const;
|
| 3042 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3043 |
};
|
|
|
|
| 3044 |
```
|
| 3045 |
|
| 3046 |
``` cpp
|
| 3047 |
explicit weibull_distribution(RealType a, RealType b = 1.0);
|
| 3048 |
```
|
|
@@ -3068,15 +2945,18 @@ constructed.
|
|
| 3068 |
|
| 3069 |
##### Class template `extreme_value_distribution` <a id="rand.dist.pois.extreme">[[rand.dist.pois.extreme]]</a>
|
| 3070 |
|
| 3071 |
An `extreme_value_distribution` random number distribution produces
|
| 3072 |
random numbers x distributed according to the probability density
|
| 3073 |
-
function[^
|
|
|
|
|
|
|
| 3074 |
\cdot \exp\left(\frac{a-x}{b} - \exp\left(\frac{a-x}{b}\right)\right)
|
| 3075 |
\text{ .}$$
|
| 3076 |
|
| 3077 |
``` cpp
|
|
|
|
| 3078 |
template<class RealType = double>
|
| 3079 |
class extreme_value_distribution {
|
| 3080 |
public:
|
| 3081 |
// types
|
| 3082 |
using result_type = RealType;
|
|
@@ -3086,10 +2966,14 @@ template<class RealType = double>
|
|
| 3086 |
extreme_value_distribution() : extreme_value_distribution(0.0) {}
|
| 3087 |
explicit extreme_value_distribution(RealType a, RealType b = 1.0);
|
| 3088 |
explicit extreme_value_distribution(const param_type& parm);
|
| 3089 |
void reset();
|
| 3090 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3091 |
// generating functions
|
| 3092 |
template<class URBG>
|
| 3093 |
result_type operator()(URBG& g);
|
| 3094 |
template<class URBG>
|
| 3095 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3099,11 +2983,20 @@ template<class RealType = double>
|
|
| 3099 |
RealType b() const;
|
| 3100 |
param_type param() const;
|
| 3101 |
void param(const param_type& parm);
|
| 3102 |
result_type min() const;
|
| 3103 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3104 |
};
|
|
|
|
| 3105 |
```
|
| 3106 |
|
| 3107 |
``` cpp
|
| 3108 |
explicit extreme_value_distribution(RealType a, RealType b = 1.0);
|
| 3109 |
```
|
|
@@ -3143,10 +3036,11 @@ numbers x distributed according to the probability density function $$%
|
|
| 3143 |
}
|
| 3144 |
\text{ .}$$ The distribution parameters μ and σ are also known as this
|
| 3145 |
distribution’s *mean* and *standard deviation*.
|
| 3146 |
|
| 3147 |
``` cpp
|
|
|
|
| 3148 |
template<class RealType = double>
|
| 3149 |
class normal_distribution {
|
| 3150 |
public:
|
| 3151 |
// types
|
| 3152 |
using result_type = RealType;
|
|
@@ -3156,10 +3050,13 @@ template<class RealType = double>
|
|
| 3156 |
normal_distribution() : normal_distribution(0.0) {}
|
| 3157 |
explicit normal_distribution(RealType mean, RealType stddev = 1.0);
|
| 3158 |
explicit normal_distribution(const param_type& parm);
|
| 3159 |
void reset();
|
| 3160 |
|
|
|
|
|
|
|
|
|
|
| 3161 |
// generating functions
|
| 3162 |
template<class URBG>
|
| 3163 |
result_type operator()(URBG& g);
|
| 3164 |
template<class URBG>
|
| 3165 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3169,11 +3066,20 @@ template<class RealType = double>
|
|
| 3169 |
RealType stddev() const;
|
| 3170 |
param_type param() const;
|
| 3171 |
void param(const param_type& parm);
|
| 3172 |
result_type min() const;
|
| 3173 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3174 |
};
|
|
|
|
| 3175 |
```
|
| 3176 |
|
| 3177 |
``` cpp
|
| 3178 |
explicit normal_distribution(RealType mean, RealType stddev = 1.0);
|
| 3179 |
```
|
|
@@ -3204,10 +3110,11 @@ numbers x > 0 distributed according to the probability density function
|
|
| 3204 |
$$p(x\,|\,m,s) = \frac{1}{s x \sqrt{2 \pi}}
|
| 3205 |
\cdot \exp{\left(-\frac{(\ln{x} - m)^2}{2 s^2}\right)}
|
| 3206 |
\text{ .}$$
|
| 3207 |
|
| 3208 |
``` cpp
|
|
|
|
| 3209 |
template<class RealType = double>
|
| 3210 |
class lognormal_distribution {
|
| 3211 |
public:
|
| 3212 |
// types
|
| 3213 |
using result_type = RealType;
|
|
@@ -3217,10 +3124,13 @@ template<class RealType = double>
|
|
| 3217 |
lognormal_distribution() : lognormal_distribution(0.0) {}
|
| 3218 |
explicit lognormal_distribution(RealType m, RealType s = 1.0);
|
| 3219 |
explicit lognormal_distribution(const param_type& parm);
|
| 3220 |
void reset();
|
| 3221 |
|
|
|
|
|
|
|
|
|
|
| 3222 |
// generating functions
|
| 3223 |
template<class URBG>
|
| 3224 |
result_type operator()(URBG& g);
|
| 3225 |
template<class URBG>
|
| 3226 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3230,11 +3140,20 @@ template<class RealType = double>
|
|
| 3230 |
RealType s() const;
|
| 3231 |
param_type param() const;
|
| 3232 |
void param(const param_type& parm);
|
| 3233 |
result_type min() const;
|
| 3234 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3235 |
};
|
|
|
|
| 3236 |
```
|
| 3237 |
|
| 3238 |
``` cpp
|
| 3239 |
explicit lognormal_distribution(RealType m, RealType s = 1.0);
|
| 3240 |
```
|
|
@@ -3263,10 +3182,11 @@ constructed.
|
|
| 3263 |
A `chi_squared_distribution` random number distribution produces random
|
| 3264 |
numbers x > 0 distributed according to the probability density function
|
| 3265 |
$$p(x\,|\,n) = \frac{x^{(n/2)-1} \cdot e^{-x/2}}{\Gamma(n/2) \cdot 2^{n/2}} \text{ .}$$
|
| 3266 |
|
| 3267 |
``` cpp
|
|
|
|
| 3268 |
template<class RealType = double>
|
| 3269 |
class chi_squared_distribution {
|
| 3270 |
public:
|
| 3271 |
// types
|
| 3272 |
using result_type = RealType;
|
|
@@ -3276,10 +3196,13 @@ template<class RealType = double>
|
|
| 3276 |
chi_squared_distribution() : chi_squared_distribution(1.0) {}
|
| 3277 |
explicit chi_squared_distribution(RealType n);
|
| 3278 |
explicit chi_squared_distribution(const param_type& parm);
|
| 3279 |
void reset();
|
| 3280 |
|
|
|
|
|
|
|
|
|
|
| 3281 |
// generating functions
|
| 3282 |
template<class URBG>
|
| 3283 |
result_type operator()(URBG& g);
|
| 3284 |
template<class URBG>
|
| 3285 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3288,11 +3211,20 @@ template<class RealType = double>
|
|
| 3288 |
RealType n() const;
|
| 3289 |
param_type param() const;
|
| 3290 |
void param(const param_type& parm);
|
| 3291 |
result_type min() const;
|
| 3292 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3293 |
};
|
|
|
|
| 3294 |
```
|
| 3295 |
|
| 3296 |
``` cpp
|
| 3297 |
explicit chi_squared_distribution(RealType n);
|
| 3298 |
```
|
|
@@ -3313,10 +3245,11 @@ constructed.
|
|
| 3313 |
A `cauchy_distribution` random number distribution produces random
|
| 3314 |
numbers x distributed according to the probability density function
|
| 3315 |
$$p(x\,|\,a,b) = \left(\pi b \left(1 + \left(\frac{x-a}{b} \right)^2 \, \right)\right)^{-1} \text{ .}$$
|
| 3316 |
|
| 3317 |
``` cpp
|
|
|
|
| 3318 |
template<class RealType = double>
|
| 3319 |
class cauchy_distribution {
|
| 3320 |
public:
|
| 3321 |
// types
|
| 3322 |
using result_type = RealType;
|
|
@@ -3326,10 +3259,13 @@ template<class RealType = double>
|
|
| 3326 |
cauchy_distribution() : cauchy_distribution(0.0) {}
|
| 3327 |
explicit cauchy_distribution(RealType a, RealType b = 1.0);
|
| 3328 |
explicit cauchy_distribution(const param_type& parm);
|
| 3329 |
void reset();
|
| 3330 |
|
|
|
|
|
|
|
|
|
|
| 3331 |
// generating functions
|
| 3332 |
template<class URBG>
|
| 3333 |
result_type operator()(URBG& g);
|
| 3334 |
template<class URBG>
|
| 3335 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3339,11 +3275,20 @@ template<class RealType = double>
|
|
| 3339 |
RealType b() const;
|
| 3340 |
param_type param() const;
|
| 3341 |
void param(const param_type& parm);
|
| 3342 |
result_type min() const;
|
| 3343 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3344 |
};
|
|
|
|
| 3345 |
```
|
| 3346 |
|
| 3347 |
``` cpp
|
| 3348 |
explicit cauchy_distribution(RealType a, RealType b = 1.0);
|
| 3349 |
```
|
|
@@ -3376,10 +3321,11 @@ $$p(x\,|\,m,n) = \frac{\Gamma\big((m+n)/2\big)}{\Gamma(m/2) \; \Gamma(n/2)}
|
|
| 3376 |
\cdot x^{(m/2)-1}
|
| 3377 |
\cdot \left(1 + \frac{m x}{n}\right)^{-(m + n)/2}
|
| 3378 |
\text{ .}$$
|
| 3379 |
|
| 3380 |
``` cpp
|
|
|
|
| 3381 |
template<class RealType = double>
|
| 3382 |
class fisher_f_distribution {
|
| 3383 |
public:
|
| 3384 |
// types
|
| 3385 |
using result_type = RealType;
|
|
@@ -3389,10 +3335,13 @@ template<class RealType = double>
|
|
| 3389 |
fisher_f_distribution() : fisher_f_distribution(1.0) {}
|
| 3390 |
explicit fisher_f_distribution(RealType m, RealType n = 1.0);
|
| 3391 |
explicit fisher_f_distribution(const param_type& parm);
|
| 3392 |
void reset();
|
| 3393 |
|
|
|
|
|
|
|
|
|
|
| 3394 |
// generating functions
|
| 3395 |
template<class URBG>
|
| 3396 |
result_type operator()(URBG& g);
|
| 3397 |
template<class URBG>
|
| 3398 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3402,11 +3351,20 @@ template<class RealType = double>
|
|
| 3402 |
RealType n() const;
|
| 3403 |
param_type param() const;
|
| 3404 |
void param(const param_type& parm);
|
| 3405 |
result_type min() const;
|
| 3406 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3407 |
};
|
|
|
|
| 3408 |
```
|
| 3409 |
|
| 3410 |
``` cpp
|
| 3411 |
explicit fisher_f_distribution(RealType m, RealType n = 1);
|
| 3412 |
```
|
|
@@ -3438,10 +3396,11 @@ $$p(x\,|\,n) = \frac{1}{\sqrt{n \pi}}
|
|
| 3438 |
\cdot \frac{\Gamma\big((n+1)/2\big)}{\Gamma(n/2)}
|
| 3439 |
\cdot \left(1 + \frac{x^2}{n} \right)^{-(n+1)/2}
|
| 3440 |
\text{ .}$$
|
| 3441 |
|
| 3442 |
``` cpp
|
|
|
|
| 3443 |
template<class RealType = double>
|
| 3444 |
class student_t_distribution {
|
| 3445 |
public:
|
| 3446 |
// types
|
| 3447 |
using result_type = RealType;
|
|
@@ -3451,10 +3410,13 @@ template<class RealType = double>
|
|
| 3451 |
student_t_distribution() : student_t_distribution(1.0) {}
|
| 3452 |
explicit student_t_distribution(RealType n);
|
| 3453 |
explicit student_t_distribution(const param_type& parm);
|
| 3454 |
void reset();
|
| 3455 |
|
|
|
|
|
|
|
|
|
|
| 3456 |
// generating functions
|
| 3457 |
template<class URBG>
|
| 3458 |
result_type operator()(URBG& g);
|
| 3459 |
template<class URBG>
|
| 3460 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3463,11 +3425,20 @@ template<class RealType = double>
|
|
| 3463 |
RealType n() const;
|
| 3464 |
param_type param() const;
|
| 3465 |
void param(const param_type& parm);
|
| 3466 |
result_type min() const;
|
| 3467 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3468 |
};
|
|
|
|
| 3469 |
```
|
| 3470 |
|
| 3471 |
``` cpp
|
| 3472 |
explicit student_t_distribution(RealType n);
|
| 3473 |
```
|
|
@@ -3496,10 +3467,11 @@ as: pₖ = {wₖ / S} for k = 0, …, n - 1, in which the values wₖ, commonly
|
|
| 3496 |
known as the *weights* , shall be non-negative, non-NaN, and
|
| 3497 |
non-infinity. Moreover, the following relation shall hold:
|
| 3498 |
$0 < S = w_0 + \dotsb + w_{n - 1}$.
|
| 3499 |
|
| 3500 |
``` cpp
|
|
|
|
| 3501 |
template<class IntType = int>
|
| 3502 |
class discrete_distribution {
|
| 3503 |
public:
|
| 3504 |
// types
|
| 3505 |
using result_type = IntType;
|
|
@@ -3513,10 +3485,13 @@ template<class IntType = int>
|
|
| 3513 |
template<class UnaryOperation>
|
| 3514 |
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
|
| 3515 |
explicit discrete_distribution(const param_type& parm);
|
| 3516 |
void reset();
|
| 3517 |
|
|
|
|
|
|
|
|
|
|
| 3518 |
// generating functions
|
| 3519 |
template<class URBG>
|
| 3520 |
result_type operator()(URBG& g);
|
| 3521 |
template<class URBG>
|
| 3522 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3525,11 +3500,20 @@ template<class IntType = int>
|
|
| 3525 |
vector<double> probabilities() const;
|
| 3526 |
param_type param() const;
|
| 3527 |
void param(const param_type& parm);
|
| 3528 |
result_type min() const;
|
| 3529 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3530 |
};
|
|
|
|
| 3531 |
```
|
| 3532 |
|
| 3533 |
``` cpp
|
| 3534 |
discrete_distribution();
|
| 3535 |
```
|
|
@@ -3605,10 +3589,11 @@ $$\rho_k = \frac{w_k}{S \cdot (b_{k+1}-b_k)} \text{ for } k = 0, \dotsc, n - 1 \
|
|
| 3605 |
in which the values wₖ, commonly known as the *weights* , shall be
|
| 3606 |
non-negative, non-NaN, and non-infinity. Moreover, the following
|
| 3607 |
relation shall hold: 0 < S = w₀ + … + wₙ₋₁.
|
| 3608 |
|
| 3609 |
``` cpp
|
|
|
|
| 3610 |
template<class RealType = double>
|
| 3611 |
class piecewise_constant_distribution {
|
| 3612 |
public:
|
| 3613 |
// types
|
| 3614 |
using result_type = RealType;
|
|
@@ -3625,10 +3610,14 @@ template<class RealType = double>
|
|
| 3625 |
piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax,
|
| 3626 |
UnaryOperation fw);
|
| 3627 |
explicit piecewise_constant_distribution(const param_type& parm);
|
| 3628 |
void reset();
|
| 3629 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3630 |
// generating functions
|
| 3631 |
template<class URBG>
|
| 3632 |
result_type operator()(URBG& g);
|
| 3633 |
template<class URBG>
|
| 3634 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3638,11 +3627,20 @@ template<class RealType = double>
|
|
| 3638 |
vector<result_type> densities() const;
|
| 3639 |
param_type param() const;
|
| 3640 |
void param(const param_type& parm);
|
| 3641 |
result_type min() const;
|
| 3642 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3643 |
};
|
|
|
|
| 3644 |
```
|
| 3645 |
|
| 3646 |
``` cpp
|
| 3647 |
piecewise_constant_distribution();
|
| 3648 |
```
|
|
@@ -3741,10 +3739,11 @@ in which the values wₖ, commonly known as the *weights at boundaries* ,
|
|
| 3741 |
shall be non-negative, non-NaN, and non-infinity. Moreover, the
|
| 3742 |
following relation shall hold:
|
| 3743 |
$$0 < S = \frac{1}{2} \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k) \text{ .}$$
|
| 3744 |
|
| 3745 |
``` cpp
|
|
|
|
| 3746 |
template<class RealType = double>
|
| 3747 |
class piecewise_linear_distribution {
|
| 3748 |
public:
|
| 3749 |
// types
|
| 3750 |
using result_type = RealType;
|
|
@@ -3760,10 +3759,14 @@ template<class RealType = double>
|
|
| 3760 |
template<class UnaryOperation>
|
| 3761 |
piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
|
| 3762 |
explicit piecewise_linear_distribution(const param_type& parm);
|
| 3763 |
void reset();
|
| 3764 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3765 |
// generating functions
|
| 3766 |
template<class URBG>
|
| 3767 |
result_type operator()(URBG& g);
|
| 3768 |
template<class URBG>
|
| 3769 |
result_type operator()(URBG& g, const param_type& parm);
|
|
@@ -3773,11 +3776,20 @@ template<class RealType = double>
|
|
| 3773 |
vector<result_type> densities() const;
|
| 3774 |
param_type param() const;
|
| 3775 |
void param(const param_type& parm);
|
| 3776 |
result_type min() const;
|
| 3777 |
result_type max() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3778 |
};
|
|
|
|
| 3779 |
```
|
| 3780 |
|
| 3781 |
``` cpp
|
| 3782 |
piecewise_linear_distribution();
|
| 3783 |
```
|
|
@@ -3881,11 +3893,11 @@ See also: ISO C 7.22.2
|
|
| 3881 |
## Numeric arrays <a id="numarray">[[numarray]]</a>
|
| 3882 |
|
| 3883 |
### Header `<valarray>` synopsis <a id="valarray.syn">[[valarray.syn]]</a>
|
| 3884 |
|
| 3885 |
``` cpp
|
| 3886 |
-
#include <initializer_list>
|
| 3887 |
|
| 3888 |
namespace std {
|
| 3889 |
template<class T> class valarray; // An array of type T
|
| 3890 |
class slice; // a BLAS-like slice out of an array
|
| 3891 |
template<class T> class slice_array;
|
|
@@ -4044,11 +4056,11 @@ aliasing, thus allowing operations on these classes to be optimized.
|
|
| 4044 |
|
| 4045 |
Any function returning a `valarray<T>` is permitted to return an object
|
| 4046 |
of another type, provided all the const member functions of
|
| 4047 |
`valarray<T>` are also applicable to this type. This return type shall
|
| 4048 |
not add more than two levels of template nesting over the most deeply
|
| 4049 |
-
nested argument type.[^
|
| 4050 |
|
| 4051 |
Implementations introducing such replacement types shall provide
|
| 4052 |
additional functions and operators as follows:
|
| 4053 |
|
| 4054 |
- for every function taking a `const valarray<T>&` other than `begin`
|
|
@@ -4169,19 +4181,19 @@ elements numbered sequentially from zero. It is a representation of the
|
|
| 4169 |
mathematical concept of an ordered set of values. For convenience, an
|
| 4170 |
object of type `valarray<T>` is referred to as an “array” throughout the
|
| 4171 |
remainder of [[numarray]]. The illusion of higher dimensionality may be
|
| 4172 |
produced by the familiar idiom of computed indices, together with the
|
| 4173 |
powerful subsetting capabilities provided by the generalized subscript
|
| 4174 |
-
operators.[^
|
| 4175 |
|
| 4176 |
#### Constructors <a id="valarray.cons">[[valarray.cons]]</a>
|
| 4177 |
|
| 4178 |
``` cpp
|
| 4179 |
valarray();
|
| 4180 |
```
|
| 4181 |
|
| 4182 |
-
*Effects:* Constructs a `valarray` that has zero length.[^
|
| 4183 |
|
| 4184 |
``` cpp
|
| 4185 |
explicit valarray(size_t n);
|
| 4186 |
```
|
| 4187 |
|
|
@@ -4201,19 +4213,19 @@ valarray(const T* p, size_t n);
|
|
| 4201 |
|
| 4202 |
*Preconditions:* \[`p`, `p + n`) is a valid range.
|
| 4203 |
|
| 4204 |
*Effects:* Constructs a `valarray` that has length `n`. The values of
|
| 4205 |
the elements of the array are initialized with the first `n` values
|
| 4206 |
-
pointed to by the first argument.[^
|
| 4207 |
|
| 4208 |
``` cpp
|
| 4209 |
valarray(const valarray& v);
|
| 4210 |
```
|
| 4211 |
|
| 4212 |
*Effects:* Constructs a `valarray` that has the same length as `v`. The
|
| 4213 |
elements are initialized with the values of the corresponding elements
|
| 4214 |
-
of `v`.[^
|
| 4215 |
|
| 4216 |
``` cpp
|
| 4217 |
valarray(valarray&& v) noexcept;
|
| 4218 |
```
|
| 4219 |
|
|
@@ -4324,12 +4336,12 @@ evaluates to `true` for all `size_t i` and `size_t j` such that
|
|
| 4324 |
|
| 4325 |
The expression `addressof(a[i]) != addressof(b[j])` evaluates to `true`
|
| 4326 |
for any two arrays `a` and `b` and for any `size_t i` and `size_t j`
|
| 4327 |
such that `i < a.size()` and `j < b.size()`.
|
| 4328 |
|
| 4329 |
-
[*Note 2*: This property indicates an absence of aliasing and
|
| 4330 |
-
used to advantage by optimizing compilers. Compilers
|
| 4331 |
of inlining, constant propagation, loop fusion, tracking of pointers
|
| 4332 |
obtained from `operator new`, and other techniques to generate efficient
|
| 4333 |
`valarray`s. — *end note*]
|
| 4334 |
|
| 4335 |
The reference returned by the subscript operator for an array shall be
|
|
@@ -4637,12 +4649,12 @@ is `(*this)[`*`I`*` + n]` if *`I`*` + n` is non-negative and less than
|
|
| 4637 |
value of `n` shifts the elements left `n` places, with zero
|
| 4638 |
fill. — *end note*]
|
| 4639 |
|
| 4640 |
[*Example 1*: If the argument has the value -2, the first two elements
|
| 4641 |
of the result will be value-initialized [[dcl.init]]; the third element
|
| 4642 |
-
of the result will be assigned the value of the first element of
|
| 4643 |
-
|
| 4644 |
|
| 4645 |
``` cpp
|
| 4646 |
valarray cshift(int n) const;
|
| 4647 |
```
|
| 4648 |
|
|
@@ -4862,10 +4874,11 @@ template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
|
|
| 4862 |
namespace std {
|
| 4863 |
class slice {
|
| 4864 |
public:
|
| 4865 |
slice();
|
| 4866 |
slice(size_t, size_t, size_t);
|
|
|
|
| 4867 |
|
| 4868 |
size_t start() const;
|
| 4869 |
size_t size() const;
|
| 4870 |
size_t stride() const;
|
| 4871 |
|
|
@@ -4873,18 +4886,17 @@ namespace std {
|
|
| 4873 |
};
|
| 4874 |
}
|
| 4875 |
```
|
| 4876 |
|
| 4877 |
The `slice` class represents a BLAS-like slice from an array. Such a
|
| 4878 |
-
slice is specified by a starting index, a length, and a stride.[^
|
| 4879 |
|
| 4880 |
#### Constructors <a id="cons.slice">[[cons.slice]]</a>
|
| 4881 |
|
| 4882 |
``` cpp
|
| 4883 |
slice();
|
| 4884 |
slice(size_t start, size_t length, size_t stride);
|
| 4885 |
-
slice(const slice&);
|
| 4886 |
```
|
| 4887 |
|
| 4888 |
The default constructor is equivalent to `slice(0, 0, 0)`. A default
|
| 4889 |
constructor is provided only to permit the declaration of arrays of
|
| 4890 |
slices. The constructor with arguments for a slice takes a start,
|
|
@@ -5069,11 +5081,10 @@ of `operator[](const gslice&)`, the behavior is undefined.
|
|
| 5069 |
|
| 5070 |
``` cpp
|
| 5071 |
gslice();
|
| 5072 |
gslice(size_t start, const valarray<size_t>& lengths,
|
| 5073 |
const valarray<size_t>& strides);
|
| 5074 |
-
gslice(const gslice&);
|
| 5075 |
```
|
| 5076 |
|
| 5077 |
The default constructor is equivalent to
|
| 5078 |
`gslice(0, valarray<size_t>(), valarray<size_t>())`. The constructor
|
| 5079 |
with arguments builds a `gslice` based on a specification of start,
|
|
@@ -5211,11 +5222,11 @@ namespace std {
|
|
| 5211 |
```
|
| 5212 |
|
| 5213 |
This template is a helper template used by the mask subscript operator:
|
| 5214 |
|
| 5215 |
``` cpp
|
| 5216 |
-
mask_array<T> valarray<T>::operator[](const valarray<bool>&)
|
| 5217 |
```
|
| 5218 |
|
| 5219 |
It has reference semantics to a subset of an array specified by a
|
| 5220 |
boolean mask. Thus, the expression `a[mask] = b;` has the effect of
|
| 5221 |
assigning the elements of `b` to the masked elements in `a` (those for
|
|
@@ -5228,11 +5239,11 @@ void operator=(const valarray<T>&) const;
|
|
| 5228 |
const mask_array& operator=(const mask_array&) const;
|
| 5229 |
```
|
| 5230 |
|
| 5231 |
These assignment operators have reference semantics, assigning the
|
| 5232 |
values of the argument array elements to selected elements of the
|
| 5233 |
-
`valarray<T>` object to which
|
| 5234 |
|
| 5235 |
#### Compound assignment <a id="mask.array.comp.assign">[[mask.array.comp.assign]]</a>
|
| 5236 |
|
| 5237 |
``` cpp
|
| 5238 |
void operator*= (const valarray<T>&) const;
|
|
@@ -5247,11 +5258,12 @@ void operator<<=(const valarray<T>&) const;
|
|
| 5247 |
void operator>>=(const valarray<T>&) const;
|
| 5248 |
```
|
| 5249 |
|
| 5250 |
These compound assignments have reference semantics, applying the
|
| 5251 |
indicated operation to the elements of the argument array and selected
|
| 5252 |
-
elements of the `valarray<T>` object to which the
|
|
|
|
| 5253 |
|
| 5254 |
#### Fill function <a id="mask.array.fill">[[mask.array.fill]]</a>
|
| 5255 |
|
| 5256 |
``` cpp
|
| 5257 |
void operator=(const T&) const;
|
|
@@ -5295,11 +5307,11 @@ namespace std {
|
|
| 5295 |
|
| 5296 |
This template is a helper template used by the indirect subscript
|
| 5297 |
operator
|
| 5298 |
|
| 5299 |
``` cpp
|
| 5300 |
-
indirect_array<T> valarray<T>::operator[](const valarray<size_t>&)
|
| 5301 |
```
|
| 5302 |
|
| 5303 |
It has reference semantics to a subset of an array specified by an
|
| 5304 |
`indirect_array`. Thus, the expression `a[{}indirect] = b;` has the
|
| 5305 |
effect of assigning the elements of `b` to the elements in `a` whose
|
|
@@ -5426,600 +5438,457 @@ namespace std {
|
|
| 5426 |
#define MATH_ERREXCEPT see below
|
| 5427 |
|
| 5428 |
#define math_errhandling see below
|
| 5429 |
|
| 5430 |
namespace std {
|
| 5431 |
-
|
| 5432 |
-
double acos(double x);
|
| 5433 |
-
long double acos(long double x); // see [library.c]
|
| 5434 |
float acosf(float x);
|
| 5435 |
long double acosl(long double x);
|
| 5436 |
|
| 5437 |
-
|
| 5438 |
-
double asin(double x);
|
| 5439 |
-
long double asin(long double x); // see [library.c]
|
| 5440 |
float asinf(float x);
|
| 5441 |
long double asinl(long double x);
|
| 5442 |
|
| 5443 |
-
|
| 5444 |
-
double atan(double x);
|
| 5445 |
-
long double atan(long double x); // see [library.c]
|
| 5446 |
float atanf(float x);
|
| 5447 |
long double atanl(long double x);
|
| 5448 |
|
| 5449 |
-
|
| 5450 |
-
double atan2(double y, double x);
|
| 5451 |
-
long double atan2(long double y, long double x); // see [library.c]
|
| 5452 |
float atan2f(float y, float x);
|
| 5453 |
long double atan2l(long double y, long double x);
|
| 5454 |
|
| 5455 |
-
|
| 5456 |
-
double cos(double x);
|
| 5457 |
-
long double cos(long double x); // see [library.c]
|
| 5458 |
float cosf(float x);
|
| 5459 |
long double cosl(long double x);
|
| 5460 |
|
| 5461 |
-
|
| 5462 |
-
double sin(double x);
|
| 5463 |
-
long double sin(long double x); // see [library.c]
|
| 5464 |
float sinf(float x);
|
| 5465 |
long double sinl(long double x);
|
| 5466 |
|
| 5467 |
-
|
| 5468 |
-
double tan(double x);
|
| 5469 |
-
long double tan(long double x); // see [library.c]
|
| 5470 |
float tanf(float x);
|
| 5471 |
long double tanl(long double x);
|
| 5472 |
|
| 5473 |
-
|
| 5474 |
-
double acosh(double x);
|
| 5475 |
-
long double acosh(long double x); // see [library.c]
|
| 5476 |
float acoshf(float x);
|
| 5477 |
long double acoshl(long double x);
|
| 5478 |
|
| 5479 |
-
|
| 5480 |
-
double asinh(double x);
|
| 5481 |
-
long double asinh(long double x); // see [library.c]
|
| 5482 |
float asinhf(float x);
|
| 5483 |
long double asinhl(long double x);
|
| 5484 |
|
| 5485 |
-
|
| 5486 |
-
double atanh(double x);
|
| 5487 |
-
long double atanh(long double x); // see [library.c]
|
| 5488 |
float atanhf(float x);
|
| 5489 |
long double atanhl(long double x);
|
| 5490 |
|
| 5491 |
-
|
| 5492 |
-
double cosh(double x);
|
| 5493 |
-
long double cosh(long double x); // see [library.c]
|
| 5494 |
float coshf(float x);
|
| 5495 |
long double coshl(long double x);
|
| 5496 |
|
| 5497 |
-
|
| 5498 |
-
double sinh(double x);
|
| 5499 |
-
long double sinh(long double x); // see [library.c]
|
| 5500 |
float sinhf(float x);
|
| 5501 |
long double sinhl(long double x);
|
| 5502 |
|
| 5503 |
-
|
| 5504 |
-
double tanh(double x);
|
| 5505 |
-
long double tanh(long double x); // see [library.c]
|
| 5506 |
float tanhf(float x);
|
| 5507 |
long double tanhl(long double x);
|
| 5508 |
|
| 5509 |
-
|
| 5510 |
-
double exp(double x);
|
| 5511 |
-
long double exp(long double x); // see [library.c]
|
| 5512 |
float expf(float x);
|
| 5513 |
long double expl(long double x);
|
| 5514 |
|
| 5515 |
-
|
| 5516 |
-
double exp2(double x);
|
| 5517 |
-
long double exp2(long double x); // see [library.c]
|
| 5518 |
float exp2f(float x);
|
| 5519 |
long double exp2l(long double x);
|
| 5520 |
|
| 5521 |
-
|
| 5522 |
-
double expm1(double x);
|
| 5523 |
-
long double expm1(long double x); // see [library.c]
|
| 5524 |
float expm1f(float x);
|
| 5525 |
long double expm1l(long double x);
|
| 5526 |
|
| 5527 |
-
|
| 5528 |
-
|
| 5529 |
-
long double
|
| 5530 |
-
float frexpf(float value, int* exp);
|
| 5531 |
-
long double frexpl(long double value, int* exp);
|
| 5532 |
|
| 5533 |
-
int ilogb(
|
| 5534 |
-
int
|
| 5535 |
-
int
|
| 5536 |
-
int ilogbf(float x);
|
| 5537 |
-
int ilogbl(long double x);
|
| 5538 |
|
| 5539 |
-
|
| 5540 |
-
|
| 5541 |
-
long double
|
| 5542 |
-
float ldexpf(float x, int exp);
|
| 5543 |
-
long double ldexpl(long double x, int exp);
|
| 5544 |
|
| 5545 |
-
|
| 5546 |
-
double log(double x);
|
| 5547 |
-
long double log(long double x); // see [library.c]
|
| 5548 |
float logf(float x);
|
| 5549 |
long double logl(long double x);
|
| 5550 |
|
| 5551 |
-
|
| 5552 |
-
double log10(double x);
|
| 5553 |
-
long double log10(long double x); // see [library.c]
|
| 5554 |
float log10f(float x);
|
| 5555 |
long double log10l(long double x);
|
| 5556 |
|
| 5557 |
-
|
| 5558 |
-
double log1p(double x);
|
| 5559 |
-
long double log1p(long double x); // see [library.c]
|
| 5560 |
float log1pf(float x);
|
| 5561 |
long double log1pl(long double x);
|
| 5562 |
|
| 5563 |
-
|
| 5564 |
-
double log2(double x);
|
| 5565 |
-
long double log2(long double x); // see [library.c]
|
| 5566 |
float log2f(float x);
|
| 5567 |
long double log2l(long double x);
|
| 5568 |
|
| 5569 |
-
|
| 5570 |
-
|
| 5571 |
-
long double
|
| 5572 |
-
float logbf(float x);
|
| 5573 |
-
long double logbl(long double x);
|
| 5574 |
|
| 5575 |
-
|
| 5576 |
-
|
| 5577 |
-
long double
|
| 5578 |
-
float modff(float value, float* iptr);
|
| 5579 |
-
long double modfl(long double value, long double* iptr);
|
| 5580 |
|
| 5581 |
-
|
| 5582 |
-
|
| 5583 |
-
long double
|
| 5584 |
-
float scalbnf(float x, int n);
|
| 5585 |
-
long double scalbnl(long double x, int n);
|
| 5586 |
|
| 5587 |
-
|
| 5588 |
-
|
| 5589 |
-
long double
|
| 5590 |
-
float scalblnf(float x, long int n);
|
| 5591 |
-
long double scalblnl(long double x, long int n);
|
| 5592 |
|
| 5593 |
-
|
| 5594 |
-
double cbrt(double x);
|
| 5595 |
-
long double cbrt(long double x); // see [library.c]
|
| 5596 |
float cbrtf(float x);
|
| 5597 |
long double cbrtl(long double x);
|
| 5598 |
|
| 5599 |
// [c.math.abs], absolute values
|
| 5600 |
-
int abs(int j);
|
| 5601 |
-
long int abs(long int j);
|
| 5602 |
-
long long int abs(long long int j);
|
| 5603 |
-
|
| 5604 |
-
double abs(double j);
|
| 5605 |
-
long double abs(long double j);
|
| 5606 |
|
| 5607 |
-
|
| 5608 |
-
|
| 5609 |
-
long double
|
| 5610 |
-
float fabsf(float x);
|
| 5611 |
-
long double fabsl(long double x);
|
| 5612 |
|
| 5613 |
-
|
| 5614 |
-
double hypot(double x, double y);
|
| 5615 |
-
long double hypot(long double x, long double y); // see [library.c]
|
| 5616 |
float hypotf(float x, float y);
|
| 5617 |
long double hypotl(long double x, long double y);
|
| 5618 |
|
| 5619 |
// [c.math.hypot3], three-dimensional hypotenuse
|
| 5620 |
-
|
| 5621 |
-
|
| 5622 |
-
long double hypot(long double x, long double y, long double z);
|
| 5623 |
|
| 5624 |
-
|
| 5625 |
-
double pow(double x, double y);
|
| 5626 |
-
long double pow(long double x, long double y); // see [library.c]
|
| 5627 |
float powf(float x, float y);
|
| 5628 |
long double powl(long double x, long double y);
|
| 5629 |
|
| 5630 |
-
|
| 5631 |
-
double sqrt(double x);
|
| 5632 |
-
long double sqrt(long double x); // see [library.c]
|
| 5633 |
float sqrtf(float x);
|
| 5634 |
long double sqrtl(long double x);
|
| 5635 |
|
| 5636 |
-
|
| 5637 |
-
double erf(double x);
|
| 5638 |
-
long double erf(long double x); // see [library.c]
|
| 5639 |
float erff(float x);
|
| 5640 |
long double erfl(long double x);
|
| 5641 |
|
| 5642 |
-
|
| 5643 |
-
double erfc(double x);
|
| 5644 |
-
long double erfc(long double x); // see [library.c]
|
| 5645 |
float erfcf(float x);
|
| 5646 |
long double erfcl(long double x);
|
| 5647 |
|
| 5648 |
-
|
| 5649 |
-
double lgamma(double x);
|
| 5650 |
-
long double lgamma(long double x); // see [library.c]
|
| 5651 |
float lgammaf(float x);
|
| 5652 |
long double lgammal(long double x);
|
| 5653 |
|
| 5654 |
-
|
| 5655 |
-
double tgamma(double x);
|
| 5656 |
-
long double tgamma(long double x); // see [library.c]
|
| 5657 |
float tgammaf(float x);
|
| 5658 |
long double tgammal(long double x);
|
| 5659 |
|
| 5660 |
-
|
| 5661 |
-
|
| 5662 |
-
long double
|
| 5663 |
-
float ceilf(float x);
|
| 5664 |
-
long double ceill(long double x);
|
| 5665 |
|
| 5666 |
-
|
| 5667 |
-
|
| 5668 |
-
long double
|
| 5669 |
-
float floorf(float x);
|
| 5670 |
-
long double floorl(long double x);
|
| 5671 |
|
| 5672 |
-
|
| 5673 |
-
double nearbyint(double x);
|
| 5674 |
-
long double nearbyint(long double x); // see [library.c]
|
| 5675 |
float nearbyintf(float x);
|
| 5676 |
long double nearbyintl(long double x);
|
| 5677 |
|
| 5678 |
-
|
| 5679 |
-
double rint(double x);
|
| 5680 |
-
long double rint(long double x); // see [library.c]
|
| 5681 |
float rintf(float x);
|
| 5682 |
long double rintl(long double x);
|
| 5683 |
|
| 5684 |
-
long int lrint(
|
| 5685 |
-
long int lrint(double x);
|
| 5686 |
-
long int lrint(long double x); // see [library.c]
|
| 5687 |
long int lrintf(float x);
|
| 5688 |
long int lrintl(long double x);
|
| 5689 |
|
| 5690 |
-
long long int llrint(
|
| 5691 |
-
long long int llrint(double x);
|
| 5692 |
-
long long int llrint(long double x); // see [library.c]
|
| 5693 |
long long int llrintf(float x);
|
| 5694 |
long long int llrintl(long double x);
|
| 5695 |
|
| 5696 |
-
|
| 5697 |
-
|
| 5698 |
-
long double
|
| 5699 |
-
float roundf(float x);
|
| 5700 |
-
long double roundl(long double x);
|
| 5701 |
|
| 5702 |
-
long int lround(
|
| 5703 |
-
long int
|
| 5704 |
-
long int
|
| 5705 |
-
long int lroundf(float x);
|
| 5706 |
-
long int lroundl(long double x);
|
| 5707 |
|
| 5708 |
-
long long int llround(
|
| 5709 |
-
long long int
|
| 5710 |
-
long long int
|
| 5711 |
-
long long int llroundf(float x);
|
| 5712 |
-
long long int llroundl(long double x);
|
| 5713 |
|
| 5714 |
-
|
| 5715 |
-
|
| 5716 |
-
long double
|
| 5717 |
-
float truncf(float x);
|
| 5718 |
-
long double truncl(long double x);
|
| 5719 |
|
| 5720 |
-
|
| 5721 |
-
|
| 5722 |
-
long double
|
| 5723 |
-
float fmodf(float x, float y);
|
| 5724 |
-
long double fmodl(long double x, long double y);
|
| 5725 |
|
| 5726 |
-
|
| 5727 |
-
|
| 5728 |
-
long double
|
| 5729 |
-
float remainderf(float x, float y);
|
| 5730 |
-
long double remainderl(long double x, long double y);
|
| 5731 |
|
| 5732 |
-
|
| 5733 |
-
|
| 5734 |
-
long double
|
| 5735 |
-
float remquof(float x, float y, int* quo);
|
| 5736 |
-
long double remquol(long double x, long double y, int* quo);
|
| 5737 |
|
| 5738 |
-
|
| 5739 |
-
|
| 5740 |
-
long double
|
| 5741 |
-
float copysignf(float x, float y);
|
| 5742 |
-
long double copysignl(long double x, long double y);
|
| 5743 |
|
| 5744 |
double nan(const char* tagp);
|
| 5745 |
float nanf(const char* tagp);
|
| 5746 |
long double nanl(const char* tagp);
|
| 5747 |
|
| 5748 |
-
|
| 5749 |
-
|
| 5750 |
-
long double
|
| 5751 |
-
float nextafterf(float x, float y);
|
| 5752 |
-
long double nextafterl(long double x, long double y);
|
| 5753 |
|
| 5754 |
-
|
| 5755 |
-
|
| 5756 |
-
long double
|
| 5757 |
-
float nexttowardf(float x, long double y);
|
| 5758 |
-
long double nexttowardl(long double x, long double y);
|
| 5759 |
|
| 5760 |
-
|
| 5761 |
-
|
| 5762 |
-
long double
|
| 5763 |
-
float fdimf(float x, float y);
|
| 5764 |
-
long double fdiml(long double x, long double y);
|
| 5765 |
|
| 5766 |
-
|
| 5767 |
-
|
| 5768 |
-
long double
|
| 5769 |
-
float fmaxf(float x, float y);
|
| 5770 |
-
long double fmaxl(long double x, long double y);
|
| 5771 |
|
| 5772 |
-
|
| 5773 |
-
|
| 5774 |
-
long double
|
| 5775 |
-
float fminf(float x, float y);
|
| 5776 |
-
long double fminl(long double x, long double y);
|
| 5777 |
|
| 5778 |
-
|
| 5779 |
-
|
| 5780 |
-
|
| 5781 |
-
|
| 5782 |
-
long double fmal(long double x, long double y, long double z);
|
| 5783 |
|
| 5784 |
// [c.math.lerp], linear interpolation
|
| 5785 |
-
constexpr
|
| 5786 |
-
|
| 5787 |
-
constexpr long double lerp(long double a, long double b, long double t) noexcept;
|
| 5788 |
|
| 5789 |
// [c.math.fpclass], classification / comparison functions
|
| 5790 |
-
int fpclassify(
|
| 5791 |
-
|
| 5792 |
-
|
| 5793 |
-
|
| 5794 |
-
bool
|
| 5795 |
-
bool
|
| 5796 |
-
bool
|
| 5797 |
-
|
| 5798 |
-
bool
|
| 5799 |
-
bool
|
| 5800 |
-
bool
|
| 5801 |
-
|
| 5802 |
-
bool isnan(float x);
|
| 5803 |
-
bool isnan(double x);
|
| 5804 |
-
bool isnan(long double x);
|
| 5805 |
-
|
| 5806 |
-
bool isnormal(float x);
|
| 5807 |
-
bool isnormal(double x);
|
| 5808 |
-
bool isnormal(long double x);
|
| 5809 |
-
|
| 5810 |
-
bool signbit(float x);
|
| 5811 |
-
bool signbit(double x);
|
| 5812 |
-
bool signbit(long double x);
|
| 5813 |
-
|
| 5814 |
-
bool isgreater(float x, float y);
|
| 5815 |
-
bool isgreater(double x, double y);
|
| 5816 |
-
bool isgreater(long double x, long double y);
|
| 5817 |
-
|
| 5818 |
-
bool isgreaterequal(float x, float y);
|
| 5819 |
-
bool isgreaterequal(double x, double y);
|
| 5820 |
-
bool isgreaterequal(long double x, long double y);
|
| 5821 |
-
|
| 5822 |
-
bool isless(float x, float y);
|
| 5823 |
-
bool isless(double x, double y);
|
| 5824 |
-
bool isless(long double x, long double y);
|
| 5825 |
-
|
| 5826 |
-
bool islessequal(float x, float y);
|
| 5827 |
-
bool islessequal(double x, double y);
|
| 5828 |
-
bool islessequal(long double x, long double y);
|
| 5829 |
-
|
| 5830 |
-
bool islessgreater(float x, float y);
|
| 5831 |
-
bool islessgreater(double x, double y);
|
| 5832 |
-
bool islessgreater(long double x, long double y);
|
| 5833 |
-
|
| 5834 |
-
bool isunordered(float x, float y);
|
| 5835 |
-
bool isunordered(double x, double y);
|
| 5836 |
-
bool isunordered(long double x, long double y);
|
| 5837 |
|
| 5838 |
// [sf.cmath], mathematical special functions
|
| 5839 |
|
| 5840 |
// [sf.cmath.assoc.laguerre], associated Laguerre polynomials
|
| 5841 |
-
|
| 5842 |
float assoc_laguerref(unsigned n, unsigned m, float x);
|
| 5843 |
long double assoc_laguerrel(unsigned n, unsigned m, long double x);
|
| 5844 |
|
| 5845 |
// [sf.cmath.assoc.legendre], associated Legendre functions
|
| 5846 |
-
|
| 5847 |
float assoc_legendref(unsigned l, unsigned m, float x);
|
| 5848 |
long double assoc_legendrel(unsigned l, unsigned m, long double x);
|
| 5849 |
|
| 5850 |
// [sf.cmath.beta], beta function
|
| 5851 |
-
|
| 5852 |
float betaf(float x, float y);
|
| 5853 |
long double betal(long double x, long double y);
|
| 5854 |
|
| 5855 |
// [sf.cmath.comp.ellint.1], complete elliptic integral of the first kind
|
| 5856 |
-
|
| 5857 |
float comp_ellint_1f(float k);
|
| 5858 |
long double comp_ellint_1l(long double k);
|
| 5859 |
|
| 5860 |
// [sf.cmath.comp.ellint.2], complete elliptic integral of the second kind
|
| 5861 |
-
|
| 5862 |
float comp_ellint_2f(float k);
|
| 5863 |
long double comp_ellint_2l(long double k);
|
| 5864 |
|
| 5865 |
// [sf.cmath.comp.ellint.3], complete elliptic integral of the third kind
|
| 5866 |
-
|
| 5867 |
float comp_ellint_3f(float k, float nu);
|
| 5868 |
long double comp_ellint_3l(long double k, long double nu);
|
| 5869 |
|
| 5870 |
// [sf.cmath.cyl.bessel.i], regular modified cylindrical Bessel functions
|
| 5871 |
-
|
| 5872 |
float cyl_bessel_if(float nu, float x);
|
| 5873 |
long double cyl_bessel_il(long double nu, long double x);
|
| 5874 |
|
| 5875 |
// [sf.cmath.cyl.bessel.j], cylindrical Bessel functions of the first kind
|
| 5876 |
-
|
| 5877 |
float cyl_bessel_jf(float nu, float x);
|
| 5878 |
long double cyl_bessel_jl(long double nu, long double x);
|
| 5879 |
|
| 5880 |
// [sf.cmath.cyl.bessel.k], irregular modified cylindrical Bessel functions
|
| 5881 |
-
|
| 5882 |
float cyl_bessel_kf(float nu, float x);
|
| 5883 |
long double cyl_bessel_kl(long double nu, long double x);
|
| 5884 |
|
| 5885 |
-
// [sf.cmath.cyl.neumann], cylindrical Neumann functions
|
| 5886 |
// cylindrical Bessel functions of the second kind
|
| 5887 |
-
|
| 5888 |
float cyl_neumannf(float nu, float x);
|
| 5889 |
long double cyl_neumannl(long double nu, long double x);
|
| 5890 |
|
| 5891 |
// [sf.cmath.ellint.1], incomplete elliptic integral of the first kind
|
| 5892 |
-
|
| 5893 |
float ellint_1f(float k, float phi);
|
| 5894 |
long double ellint_1l(long double k, long double phi);
|
| 5895 |
|
| 5896 |
// [sf.cmath.ellint.2], incomplete elliptic integral of the second kind
|
| 5897 |
-
|
| 5898 |
float ellint_2f(float k, float phi);
|
| 5899 |
long double ellint_2l(long double k, long double phi);
|
| 5900 |
|
| 5901 |
// [sf.cmath.ellint.3], incomplete elliptic integral of the third kind
|
| 5902 |
-
|
|
|
|
| 5903 |
float ellint_3f(float k, float nu, float phi);
|
| 5904 |
long double ellint_3l(long double k, long double nu, long double phi);
|
| 5905 |
|
| 5906 |
// [sf.cmath.expint], exponential integral
|
| 5907 |
-
|
| 5908 |
float expintf(float x);
|
| 5909 |
long double expintl(long double x);
|
| 5910 |
|
| 5911 |
// [sf.cmath.hermite], Hermite polynomials
|
| 5912 |
-
|
| 5913 |
float hermitef(unsigned n, float x);
|
| 5914 |
long double hermitel(unsigned n, long double x);
|
| 5915 |
|
| 5916 |
// [sf.cmath.laguerre], Laguerre polynomials
|
| 5917 |
-
|
| 5918 |
float laguerref(unsigned n, float x);
|
| 5919 |
long double laguerrel(unsigned n, long double x);
|
| 5920 |
|
| 5921 |
// [sf.cmath.legendre], Legendre polynomials
|
| 5922 |
-
|
| 5923 |
float legendref(unsigned l, float x);
|
| 5924 |
long double legendrel(unsigned l, long double x);
|
| 5925 |
|
| 5926 |
// [sf.cmath.riemann.zeta], Riemann zeta function
|
| 5927 |
-
|
| 5928 |
float riemann_zetaf(float x);
|
| 5929 |
long double riemann_zetal(long double x);
|
| 5930 |
|
| 5931 |
// [sf.cmath.sph.bessel], spherical Bessel functions of the first kind
|
| 5932 |
-
|
| 5933 |
float sph_besself(unsigned n, float x);
|
| 5934 |
long double sph_bessell(unsigned n, long double x);
|
| 5935 |
|
| 5936 |
// [sf.cmath.sph.legendre], spherical associated Legendre functions
|
| 5937 |
-
|
| 5938 |
float sph_legendref(unsigned l, unsigned m, float theta);
|
| 5939 |
long double sph_legendrel(unsigned l, unsigned m, long double theta);
|
| 5940 |
|
| 5941 |
// [sf.cmath.sph.neumann], spherical Neumann functions;
|
| 5942 |
// spherical Bessel functions of the second kind
|
| 5943 |
-
|
| 5944 |
float sph_neumannf(unsigned n, float x);
|
| 5945 |
long double sph_neumannl(unsigned n, long double x);
|
| 5946 |
}
|
| 5947 |
```
|
| 5948 |
|
| 5949 |
The contents and meaning of the header `<cmath>` are the same as the C
|
| 5950 |
standard library header `<math.h>`, with the addition of a
|
| 5951 |
-
three-dimensional hypotenuse function
|
| 5952 |
-
|
|
|
|
| 5953 |
|
| 5954 |
[*Note 1*: Several functions have additional overloads in this
|
| 5955 |
document, but they have the same behavior as in the C standard library
|
| 5956 |
[[library.c]]. — *end note*]
|
| 5957 |
|
| 5958 |
-
For each
|
| 5959 |
-
|
| 5960 |
-
|
|
|
|
|
|
|
| 5961 |
|
| 5962 |
-
|
| 5963 |
-
|
| 5964 |
-
|
| 5965 |
-
|
| 5966 |
-
|
| 5967 |
-
|
| 5968 |
-
|
| 5969 |
-
|
| 5970 |
-
-
|
| 5971 |
-
|
|
|
|
|
|
|
| 5972 |
|
| 5973 |
-
|
| 5974 |
-
|
|
|
|
| 5975 |
|
| 5976 |
-
ISO C 7.12
|
| 5977 |
|
| 5978 |
### Absolute values <a id="c.math.abs">[[c.math.abs]]</a>
|
| 5979 |
|
| 5980 |
[*Note 1*: The headers `<cstdlib>` and `<cmath>` declare the functions
|
| 5981 |
described in this subclause. — *end note*]
|
| 5982 |
|
| 5983 |
``` cpp
|
| 5984 |
-
int abs(int j);
|
| 5985 |
-
long int abs(long int j);
|
| 5986 |
-
long long int abs(long long int j);
|
| 5987 |
-
float abs(float j);
|
| 5988 |
-
double abs(double j);
|
| 5989 |
-
long double abs(long double j);
|
| 5990 |
```
|
| 5991 |
|
| 5992 |
-
*Effects:*
|
| 5993 |
-
standard library for the functions `abs`, `labs`, `llabs`,
|
| 5994 |
-
|
| 5995 |
|
| 5996 |
-
*Remarks:* If `abs
|
| 5997 |
`is_unsigned_v<X>` is `true` and if `X` cannot be converted to `int` by
|
| 5998 |
integral promotion [[conv.prom]], the program is ill-formed.
|
| 5999 |
|
| 6000 |
[*Note 1*: Arguments that can be promoted to `int` are permitted for
|
| 6001 |
compatibility with C. — *end note*]
|
| 6002 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6003 |
See also: ISO C 7.12.7.2, 7.22.6.1
|
| 6004 |
|
| 6005 |
### Three-dimensional hypotenuse <a id="c.math.hypot3">[[c.math.hypot3]]</a>
|
| 6006 |
|
| 6007 |
``` cpp
|
| 6008 |
-
|
| 6009 |
-
double hypot(double x, double y, double z);
|
| 6010 |
-
long double hypot(long double x, long double y, long double z);
|
| 6011 |
```
|
| 6012 |
|
| 6013 |
*Returns:* $\sqrt{x^2+y^2+z^2}$.
|
| 6014 |
|
| 6015 |
### Linear interpolation <a id="c.math.lerp">[[c.math.lerp]]</a>
|
| 6016 |
|
| 6017 |
``` cpp
|
| 6018 |
-
constexpr
|
| 6019 |
-
|
| 6020 |
-
constexpr long double lerp(long double a, long double b, long double t) noexcept;
|
| 6021 |
```
|
| 6022 |
|
| 6023 |
*Returns:* a+t(b-a).
|
| 6024 |
|
| 6025 |
*Remarks:* Let `r` be the value returned. If
|
|
@@ -6038,35 +5907,36 @@ otherwise. For any `t1` and `t2`, the product of
|
|
| 6038 |
|
| 6039 |
### Classification / comparison functions <a id="c.math.fpclass">[[c.math.fpclass]]</a>
|
| 6040 |
|
| 6041 |
The classification / comparison functions behave the same as the C
|
| 6042 |
macros with the corresponding names defined in the C standard library.
|
| 6043 |
-
Each function is overloaded for the three floating-point types.
|
| 6044 |
|
| 6045 |
-
ISO C 7.12.3, 7.12.4
|
| 6046 |
|
| 6047 |
### Mathematical special functions <a id="sf.cmath">[[sf.cmath]]</a>
|
| 6048 |
|
| 6049 |
-
|
| 6050 |
-
subclause is a NaN (Not a Number), the function shall return a NaN but
|
| 6051 |
-
it shall not report a domain error. Otherwise, the function shall report
|
| 6052 |
-
a domain error for just those argument values for which:
|
| 6053 |
|
| 6054 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6055 |
domain and those argument values fall outside the specified domain, or
|
| 6056 |
- the corresponding mathematical function value has a nonzero imaginary
|
| 6057 |
component, or
|
| 6058 |
- the corresponding mathematical function is not mathematically
|
| 6059 |
-
defined.[^
|
| 6060 |
|
| 6061 |
Unless otherwise specified, each function is defined for all finite
|
| 6062 |
values, for negative infinity, and for positive infinity.
|
| 6063 |
|
| 6064 |
#### Associated Laguerre polynomials <a id="sf.cmath.assoc.laguerre">[[sf.cmath.assoc.laguerre]]</a>
|
| 6065 |
|
| 6066 |
``` cpp
|
| 6067 |
-
|
| 6068 |
float assoc_laguerref(unsigned n, unsigned m, float x);
|
| 6069 |
long double assoc_laguerrel(unsigned n, unsigned m, long double x);
|
| 6070 |
```
|
| 6071 |
|
| 6072 |
*Effects:* These functions compute the associated Laguerre polynomials
|
|
@@ -6081,11 +5951,11 @@ of their respective arguments `n`, `m`, and `x`.
|
|
| 6081 |
*implementation-defined* if `n >= 128` or if `m >= 128`.
|
| 6082 |
|
| 6083 |
#### Associated Legendre functions <a id="sf.cmath.assoc.legendre">[[sf.cmath.assoc.legendre]]</a>
|
| 6084 |
|
| 6085 |
``` cpp
|
| 6086 |
-
|
| 6087 |
float assoc_legendref(unsigned l, unsigned m, float x);
|
| 6088 |
long double assoc_legendrel(unsigned l, unsigned m, long double x);
|
| 6089 |
```
|
| 6090 |
|
| 6091 |
*Effects:* These functions compute the associated Legendre functions of
|
|
@@ -6100,11 +5970,11 @@ their respective arguments `l`, `m`, and `x`.
|
|
| 6100 |
*implementation-defined* if `l >= 128`.
|
| 6101 |
|
| 6102 |
#### Beta function <a id="sf.cmath.beta">[[sf.cmath.beta]]</a>
|
| 6103 |
|
| 6104 |
``` cpp
|
| 6105 |
-
|
| 6106 |
float betaf(float x, float y);
|
| 6107 |
long double betal(long double x, long double y);
|
| 6108 |
```
|
| 6109 |
|
| 6110 |
*Effects:* These functions compute the beta function of their respective
|
|
@@ -6115,11 +5985,11 @@ $$\mathsf{B}(x, y) = \frac{\Gamma(x) \, \Gamma(y)}{\Gamma(x + y)}
|
|
| 6115 |
\text{ ,\quad for $x > 0$,\, $y > 0$,}$$ where x is `x` and y is `y`.
|
| 6116 |
|
| 6117 |
#### Complete elliptic integral of the first kind <a id="sf.cmath.comp.ellint.1">[[sf.cmath.comp.ellint.1]]</a>
|
| 6118 |
|
| 6119 |
``` cpp
|
| 6120 |
-
|
| 6121 |
float comp_ellint_1f(float k);
|
| 6122 |
long double comp_ellint_1l(long double k);
|
| 6123 |
```
|
| 6124 |
|
| 6125 |
*Effects:* These functions compute the complete elliptic integral of the
|
|
@@ -6132,11 +6002,11 @@ where k is `k`.
|
|
| 6132 |
See also [[sf.cmath.ellint.1]].
|
| 6133 |
|
| 6134 |
#### Complete elliptic integral of the second kind <a id="sf.cmath.comp.ellint.2">[[sf.cmath.comp.ellint.2]]</a>
|
| 6135 |
|
| 6136 |
``` cpp
|
| 6137 |
-
|
| 6138 |
float comp_ellint_2f(float k);
|
| 6139 |
long double comp_ellint_2l(long double k);
|
| 6140 |
```
|
| 6141 |
|
| 6142 |
*Effects:* These functions compute the complete elliptic integral of the
|
|
@@ -6149,11 +6019,11 @@ where k is `k`.
|
|
| 6149 |
See also [[sf.cmath.ellint.2]].
|
| 6150 |
|
| 6151 |
#### Complete elliptic integral of the third kind <a id="sf.cmath.comp.ellint.3">[[sf.cmath.comp.ellint.3]]</a>
|
| 6152 |
|
| 6153 |
``` cpp
|
| 6154 |
-
|
| 6155 |
float comp_ellint_3f(float k, float nu);
|
| 6156 |
long double comp_ellint_3l(long double k, long double nu);
|
| 6157 |
```
|
| 6158 |
|
| 6159 |
*Effects:* These functions compute the complete elliptic integral of the
|
|
@@ -6166,11 +6036,11 @@ where k is `k` and $\nu$ is `nu`.
|
|
| 6166 |
See also [[sf.cmath.ellint.3]].
|
| 6167 |
|
| 6168 |
#### Regular modified cylindrical Bessel functions <a id="sf.cmath.cyl.bessel.i">[[sf.cmath.cyl.bessel.i]]</a>
|
| 6169 |
|
| 6170 |
``` cpp
|
| 6171 |
-
|
| 6172 |
float cyl_bessel_if(float nu, float x);
|
| 6173 |
long double cyl_bessel_il(long double nu, long double x);
|
| 6174 |
```
|
| 6175 |
|
| 6176 |
*Effects:* These functions compute the regular modified cylindrical
|
|
@@ -6187,11 +6057,11 @@ Bessel functions of their respective arguments `nu` and `x`.
|
|
| 6187 |
See also [[sf.cmath.cyl.bessel.j]].
|
| 6188 |
|
| 6189 |
#### Cylindrical Bessel functions of the first kind <a id="sf.cmath.cyl.bessel.j">[[sf.cmath.cyl.bessel.j]]</a>
|
| 6190 |
|
| 6191 |
``` cpp
|
| 6192 |
-
|
| 6193 |
float cyl_bessel_jf(float nu, float x);
|
| 6194 |
long double cyl_bessel_jl(long double nu, long double x);
|
| 6195 |
```
|
| 6196 |
|
| 6197 |
*Effects:* These functions compute the cylindrical Bessel functions of
|
|
@@ -6205,11 +6075,11 @@ the first kind of their respective arguments `nu` and `x`.
|
|
| 6205 |
*implementation-defined* if `nu >= 128`.
|
| 6206 |
|
| 6207 |
#### Irregular modified cylindrical Bessel functions <a id="sf.cmath.cyl.bessel.k">[[sf.cmath.cyl.bessel.k]]</a>
|
| 6208 |
|
| 6209 |
``` cpp
|
| 6210 |
-
|
| 6211 |
float cyl_bessel_kf(float nu, float x);
|
| 6212 |
long double cyl_bessel_kl(long double nu, long double x);
|
| 6213 |
```
|
| 6214 |
|
| 6215 |
*Effects:* These functions compute the irregular modified cylindrical
|
|
@@ -6245,11 +6115,11 @@ See also [[sf.cmath.cyl.bessel.i]], [[sf.cmath.cyl.bessel.j]],
|
|
| 6245 |
[[sf.cmath.cyl.neumann]].
|
| 6246 |
|
| 6247 |
#### Cylindrical Neumann functions <a id="sf.cmath.cyl.neumann">[[sf.cmath.cyl.neumann]]</a>
|
| 6248 |
|
| 6249 |
``` cpp
|
| 6250 |
-
|
| 6251 |
float cyl_neumannf(float nu, float x);
|
| 6252 |
long double cyl_neumannl(long double nu, long double x);
|
| 6253 |
```
|
| 6254 |
|
| 6255 |
*Effects:* These functions compute the cylindrical Neumann functions,
|
|
@@ -6279,11 +6149,11 @@ their respective arguments `nu` and `x`.
|
|
| 6279 |
See also [[sf.cmath.cyl.bessel.j]].
|
| 6280 |
|
| 6281 |
#### Incomplete elliptic integral of the first kind <a id="sf.cmath.ellint.1">[[sf.cmath.ellint.1]]</a>
|
| 6282 |
|
| 6283 |
``` cpp
|
| 6284 |
-
|
| 6285 |
float ellint_1f(float k, float phi);
|
| 6286 |
long double ellint_1l(long double k, long double phi);
|
| 6287 |
```
|
| 6288 |
|
| 6289 |
*Effects:* These functions compute the incomplete elliptic integral of
|
|
@@ -6295,11 +6165,11 @@ measured in radians).
|
|
| 6295 |
\text{ ,\quad for $|k| \le 1$,}$$ where k is `k` and φ is `phi`.
|
| 6296 |
|
| 6297 |
#### Incomplete elliptic integral of the second kind <a id="sf.cmath.ellint.2">[[sf.cmath.ellint.2]]</a>
|
| 6298 |
|
| 6299 |
``` cpp
|
| 6300 |
-
|
| 6301 |
float ellint_2f(float k, float phi);
|
| 6302 |
long double ellint_2l(long double k, long double phi);
|
| 6303 |
```
|
| 6304 |
|
| 6305 |
*Effects:* These functions compute the incomplete elliptic integral of
|
|
@@ -6311,11 +6181,12 @@ $$\mathsf{E}(k, \phi) = \int_0^\phi \! \sqrt{1 - k^2 \sin^2 \theta} \, \mathsf{d
|
|
| 6311 |
\text{ ,\quad for $|k| \le 1$,}$$ where k is `k` and φ is `phi`.
|
| 6312 |
|
| 6313 |
#### Incomplete elliptic integral of the third kind <a id="sf.cmath.ellint.3">[[sf.cmath.ellint.3]]</a>
|
| 6314 |
|
| 6315 |
``` cpp
|
| 6316 |
-
|
|
|
|
| 6317 |
float ellint_3f(float k, float nu, float phi);
|
| 6318 |
long double ellint_3l(long double k, long double nu, long double phi);
|
| 6319 |
```
|
| 6320 |
|
| 6321 |
*Effects:* These functions compute the incomplete elliptic integral of
|
|
@@ -6327,11 +6198,11 @@ measured in radians).
|
|
| 6327 |
where $\nu$ is `nu`, k is `k`, and φ is `phi`.
|
| 6328 |
|
| 6329 |
#### Exponential integral <a id="sf.cmath.expint">[[sf.cmath.expint]]</a>
|
| 6330 |
|
| 6331 |
``` cpp
|
| 6332 |
-
|
| 6333 |
float expintf(float x);
|
| 6334 |
long double expintl(long double x);
|
| 6335 |
```
|
| 6336 |
|
| 6337 |
*Effects:* These functions compute the exponential integral of their
|
|
@@ -6344,11 +6215,11 @@ respective arguments `x`.
|
|
| 6344 |
\;$$ where x is `x`.
|
| 6345 |
|
| 6346 |
#### Hermite polynomials <a id="sf.cmath.hermite">[[sf.cmath.hermite]]</a>
|
| 6347 |
|
| 6348 |
``` cpp
|
| 6349 |
-
|
| 6350 |
float hermitef(unsigned n, float x);
|
| 6351 |
long double hermitel(unsigned n, long double x);
|
| 6352 |
```
|
| 6353 |
|
| 6354 |
*Effects:* These functions compute the Hermite polynomials of their
|
|
@@ -6364,11 +6235,11 @@ respective arguments `n` and `x`.
|
|
| 6364 |
*implementation-defined* if `n >= 128`.
|
| 6365 |
|
| 6366 |
#### Laguerre polynomials <a id="sf.cmath.laguerre">[[sf.cmath.laguerre]]</a>
|
| 6367 |
|
| 6368 |
``` cpp
|
| 6369 |
-
|
| 6370 |
float laguerref(unsigned n, float x);
|
| 6371 |
long double laguerrel(unsigned n, long double x);
|
| 6372 |
```
|
| 6373 |
|
| 6374 |
*Effects:* These functions compute the Laguerre polynomials of their
|
|
@@ -6382,11 +6253,11 @@ respective arguments `n` and `x`.
|
|
| 6382 |
*implementation-defined* if `n >= 128`.
|
| 6383 |
|
| 6384 |
#### Legendre polynomials <a id="sf.cmath.legendre">[[sf.cmath.legendre]]</a>
|
| 6385 |
|
| 6386 |
``` cpp
|
| 6387 |
-
|
| 6388 |
float legendref(unsigned l, float x);
|
| 6389 |
long double legendrel(unsigned l, long double x);
|
| 6390 |
```
|
| 6391 |
|
| 6392 |
*Effects:* These functions compute the Legendre polynomials of their
|
|
@@ -6401,11 +6272,11 @@ respective arguments `l` and `x`.
|
|
| 6401 |
*implementation-defined* if `l >= 128`.
|
| 6402 |
|
| 6403 |
#### Riemann zeta function <a id="sf.cmath.riemann.zeta">[[sf.cmath.riemann.zeta]]</a>
|
| 6404 |
|
| 6405 |
``` cpp
|
| 6406 |
-
|
| 6407 |
float riemann_zetaf(float x);
|
| 6408 |
long double riemann_zetal(long double x);
|
| 6409 |
```
|
| 6410 |
|
| 6411 |
*Effects:* These functions compute the Riemann zeta function of their
|
|
@@ -6435,11 +6306,11 @@ respective arguments `x`.
|
|
| 6435 |
\;$$ where x is `x`.
|
| 6436 |
|
| 6437 |
#### Spherical Bessel functions of the first kind <a id="sf.cmath.sph.bessel">[[sf.cmath.sph.bessel]]</a>
|
| 6438 |
|
| 6439 |
``` cpp
|
| 6440 |
-
|
| 6441 |
float sph_besself(unsigned n, float x);
|
| 6442 |
long double sph_bessell(unsigned n, long double x);
|
| 6443 |
```
|
| 6444 |
|
| 6445 |
*Effects:* These functions compute the spherical Bessel functions of the
|
|
@@ -6455,11 +6326,11 @@ where n is `n` and x is `x`.
|
|
| 6455 |
See also [[sf.cmath.cyl.bessel.j]].
|
| 6456 |
|
| 6457 |
#### Spherical associated Legendre functions <a id="sf.cmath.sph.legendre">[[sf.cmath.sph.legendre]]</a>
|
| 6458 |
|
| 6459 |
``` cpp
|
| 6460 |
-
|
| 6461 |
float sph_legendref(unsigned l, unsigned m, float theta);
|
| 6462 |
long double sph_legendrel(unsigned l, unsigned m, long double theta);
|
| 6463 |
```
|
| 6464 |
|
| 6465 |
*Effects:* These functions compute the spherical associated Legendre
|
|
@@ -6479,11 +6350,11 @@ is `theta`.
|
|
| 6479 |
See also [[sf.cmath.assoc.legendre]].
|
| 6480 |
|
| 6481 |
#### Spherical Neumann functions <a id="sf.cmath.sph.neumann">[[sf.cmath.sph.neumann]]</a>
|
| 6482 |
|
| 6483 |
``` cpp
|
| 6484 |
-
|
| 6485 |
float sph_neumannf(unsigned n, float x);
|
| 6486 |
long double sph_neumannl(unsigned n, long double x);
|
| 6487 |
```
|
| 6488 |
|
| 6489 |
*Effects:* These functions compute the spherical Neumann functions, also
|
|
@@ -6503,37 +6374,37 @@ See also [[sf.cmath.cyl.neumann]].
|
|
| 6503 |
|
| 6504 |
### Header `<numbers>` synopsis <a id="numbers.syn">[[numbers.syn]]</a>
|
| 6505 |
|
| 6506 |
``` cpp
|
| 6507 |
namespace std::numbers {
|
| 6508 |
-
template<class T>
|
| 6509 |
-
template<class T>
|
| 6510 |
-
template<class T>
|
| 6511 |
-
template<class T>
|
| 6512 |
-
template<class T>
|
| 6513 |
-
template<class T>
|
| 6514 |
-
template<class T>
|
| 6515 |
-
template<class T>
|
| 6516 |
-
template<class T>
|
| 6517 |
-
template<class T>
|
| 6518 |
-
template<class T>
|
| 6519 |
-
template<class T>
|
| 6520 |
-
template<class T>
|
| 6521 |
|
| 6522 |
-
template<floating_point T>
|
| 6523 |
-
template<floating_point T>
|
| 6524 |
-
template<floating_point T>
|
| 6525 |
-
template<floating_point T>
|
| 6526 |
-
template<floating_point T>
|
| 6527 |
-
template<floating_point T>
|
| 6528 |
-
template<floating_point T>
|
| 6529 |
-
template<floating_point T>
|
| 6530 |
-
template<floating_point T>
|
| 6531 |
-
template<floating_point T>
|
| 6532 |
-
template<floating_point T>
|
| 6533 |
-
template<floating_point T>
|
| 6534 |
-
template<floating_point T>
|
| 6535 |
|
| 6536 |
inline constexpr double e = e_v<double>;
|
| 6537 |
inline constexpr double log2e = log2e_v<double>;
|
| 6538 |
inline constexpr double log10e = log10e_v<double>;
|
| 6539 |
inline constexpr double pi = pi_v<double>;
|
|
@@ -6567,27 +6438,19 @@ constant variable template is ill-formed.
|
|
| 6567 |
|
| 6568 |
<!-- Link reference definitions -->
|
| 6569 |
[bad.alloc]: support.md#bad.alloc
|
| 6570 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 6571 |
[basic.stc.thread]: basic.md#basic.stc.thread
|
| 6572 |
-
[basic.types]: basic.md#basic.types
|
| 6573 |
-
[bit]: #bit
|
| 6574 |
-
[bit.cast]: #bit.cast
|
| 6575 |
-
[bit.count]: #bit.count
|
| 6576 |
-
[bit.endian]: #bit.endian
|
| 6577 |
-
[bit.general]: #bit.general
|
| 6578 |
-
[bit.pow.two]: #bit.pow.two
|
| 6579 |
-
[bit.rotate]: #bit.rotate
|
| 6580 |
-
[bit.syn]: #bit.syn
|
| 6581 |
[c.math]: #c.math
|
| 6582 |
[c.math.abs]: #c.math.abs
|
| 6583 |
[c.math.fpclass]: #c.math.fpclass
|
| 6584 |
[c.math.hypot3]: #c.math.hypot3
|
| 6585 |
[c.math.lerp]: #c.math.lerp
|
| 6586 |
[c.math.rand]: #c.math.rand
|
| 6587 |
[cfenv]: #cfenv
|
| 6588 |
[cfenv.syn]: #cfenv.syn
|
|
|
|
| 6589 |
[class.gslice]: #class.gslice
|
| 6590 |
[class.gslice.overview]: #class.gslice.overview
|
| 6591 |
[class.slice]: #class.slice
|
| 6592 |
[class.slice.overview]: #class.slice.overview
|
| 6593 |
[cmath.syn]: #cmath.syn
|
|
@@ -6595,23 +6458,22 @@ constant variable template is ill-formed.
|
|
| 6595 |
[complex]: #complex
|
| 6596 |
[complex.literals]: #complex.literals
|
| 6597 |
[complex.member.ops]: #complex.member.ops
|
| 6598 |
[complex.members]: #complex.members
|
| 6599 |
[complex.numbers]: #complex.numbers
|
|
|
|
| 6600 |
[complex.ops]: #complex.ops
|
| 6601 |
-
[complex.special]: #complex.special
|
| 6602 |
[complex.syn]: #complex.syn
|
| 6603 |
[complex.transcendentals]: #complex.transcendentals
|
| 6604 |
[complex.value.ops]: #complex.value.ops
|
| 6605 |
[cons.slice]: #cons.slice
|
| 6606 |
[conv.prom]: expr.md#conv.prom
|
| 6607 |
[cpp.pragma]: cpp.md#cpp.pragma
|
| 6608 |
[cpp17.copyassignable]: #cpp17.copyassignable
|
| 6609 |
[cpp17.copyconstructible]: #cpp17.copyconstructible
|
| 6610 |
[cpp17.equalitycomparable]: #cpp17.equalitycomparable
|
| 6611 |
[dcl.init]: dcl.md#dcl.init
|
| 6612 |
-
[expr.const]: expr.md#expr.const
|
| 6613 |
[gslice.access]: #gslice.access
|
| 6614 |
[gslice.array.assign]: #gslice.array.assign
|
| 6615 |
[gslice.array.comp.assign]: #gslice.array.comp.assign
|
| 6616 |
[gslice.array.fill]: #gslice.array.fill
|
| 6617 |
[gslice.cons]: #gslice.cons
|
|
@@ -6619,11 +6481,10 @@ constant variable template is ill-formed.
|
|
| 6619 |
[indirect.array.assign]: #indirect.array.assign
|
| 6620 |
[indirect.array.comp.assign]: #indirect.array.comp.assign
|
| 6621 |
[indirect.array.fill]: #indirect.array.fill
|
| 6622 |
[input.iterators]: iterators.md#input.iterators
|
| 6623 |
[input.output]: input.md#input.output
|
| 6624 |
-
[intro.object]: basic.md#intro.object
|
| 6625 |
[iostate.flags]: input.md#iostate.flags
|
| 6626 |
[istream.formatted]: input.md#istream.formatted
|
| 6627 |
[iterator.concept.contiguous]: iterators.md#iterator.concept.contiguous
|
| 6628 |
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 6629 |
[library.c]: library.md#library.c
|
|
@@ -6638,10 +6499,11 @@ constant variable template is ill-formed.
|
|
| 6638 |
[numeric.requirements]: #numeric.requirements
|
| 6639 |
[numerics]: #numerics
|
| 6640 |
[numerics.general]: #numerics.general
|
| 6641 |
[numerics.summary]: #numerics.summary
|
| 6642 |
[output.iterators]: iterators.md#output.iterators
|
|
|
|
| 6643 |
[rand]: #rand
|
| 6644 |
[rand.adapt]: #rand.adapt
|
| 6645 |
[rand.adapt.disc]: #rand.adapt.disc
|
| 6646 |
[rand.adapt.general]: #rand.adapt.general
|
| 6647 |
[rand.adapt.ibits]: #rand.adapt.ibits
|
|
@@ -6673,13 +6535,15 @@ constant variable template is ill-formed.
|
|
| 6673 |
[rand.dist.samp.plinear]: #rand.dist.samp.plinear
|
| 6674 |
[rand.dist.uni]: #rand.dist.uni
|
| 6675 |
[rand.dist.uni.int]: #rand.dist.uni.int
|
| 6676 |
[rand.dist.uni.real]: #rand.dist.uni.real
|
| 6677 |
[rand.eng]: #rand.eng
|
|
|
|
| 6678 |
[rand.eng.lcong]: #rand.eng.lcong
|
| 6679 |
[rand.eng.mers]: #rand.eng.mers
|
| 6680 |
[rand.eng.sub]: #rand.eng.sub
|
|
|
|
| 6681 |
[rand.predef]: #rand.predef
|
| 6682 |
[rand.req]: #rand.req
|
| 6683 |
[rand.req.adapt]: #rand.req.adapt
|
| 6684 |
[rand.req.dist]: #rand.req.dist
|
| 6685 |
[rand.req.eng]: #rand.req.eng
|
|
@@ -6705,10 +6569,11 @@ constant variable template is ill-formed.
|
|
| 6705 |
[sf.cmath.cyl.neumann]: #sf.cmath.cyl.neumann
|
| 6706 |
[sf.cmath.ellint.1]: #sf.cmath.ellint.1
|
| 6707 |
[sf.cmath.ellint.2]: #sf.cmath.ellint.2
|
| 6708 |
[sf.cmath.ellint.3]: #sf.cmath.ellint.3
|
| 6709 |
[sf.cmath.expint]: #sf.cmath.expint
|
|
|
|
| 6710 |
[sf.cmath.hermite]: #sf.cmath.hermite
|
| 6711 |
[sf.cmath.laguerre]: #sf.cmath.laguerre
|
| 6712 |
[sf.cmath.legendre]: #sf.cmath.legendre
|
| 6713 |
[sf.cmath.riemann.zeta]: #sf.cmath.riemann.zeta
|
| 6714 |
[sf.cmath.sph.bessel]: #sf.cmath.sph.bessel
|
|
@@ -6728,10 +6593,11 @@ constant variable template is ill-formed.
|
|
| 6728 |
[template.mask.array.overview]: #template.mask.array.overview
|
| 6729 |
[template.slice.array]: #template.slice.array
|
| 6730 |
[template.slice.array.overview]: #template.slice.array.overview
|
| 6731 |
[template.valarray]: #template.valarray
|
| 6732 |
[template.valarray.overview]: #template.valarray.overview
|
|
|
|
| 6733 |
[thread.jthread.class]: thread.md#thread.jthread.class
|
| 6734 |
[thread.thread.class]: thread.md#thread.thread.class
|
| 6735 |
[utility.arg.requirements]: library.md#utility.arg.requirements
|
| 6736 |
[valarray.access]: #valarray.access
|
| 6737 |
[valarray.assign]: #valarray.assign
|
|
@@ -6750,57 +6616,61 @@ constant variable template is ill-formed.
|
|
| 6750 |
|
| 6751 |
[^1]: In other words, value types. These include arithmetic types,
|
| 6752 |
pointers, the library class `complex`, and instantiations of
|
| 6753 |
`valarray` for value types.
|
| 6754 |
|
| 6755 |
-
[^2]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6756 |
period: For properly-selected values of the parameters, the period
|
| 6757 |
is closely related to a large Mersenne prime number.
|
| 6758 |
|
| 6759 |
-
[^
|
| 6760 |
differentiate between different sources of randomness.
|
| 6761 |
|
| 6762 |
-
[^
|
| 6763 |
P₀, …, Pₙ₋₁, the device entropy S is defined as
|
| 6764 |
$S = - \sum_{i=0}^{n-1} P_i \cdot \log P_i$.
|
| 6765 |
|
| 6766 |
-
[^
|
| 6767 |
randomness than can be held in `RealType`.
|
| 6768 |
|
| 6769 |
-
[^
|
| 6770 |
function is also known (with a possible change of variable) as the
|
| 6771 |
Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I
|
| 6772 |
distribution.
|
| 6773 |
|
| 6774 |
-
[^
|
| 6775 |
template instantiations. This requirement thus indirectly suggests a
|
| 6776 |
minimum allowable complexity for valarray expressions.
|
| 6777 |
|
| 6778 |
-
[^
|
| 6779 |
functionality necessary to address aliasing ambiguities and the
|
| 6780 |
proliferation of temporary objects. Thus, the `valarray` template is
|
| 6781 |
neither a matrix class nor a field class. However, it is a very
|
| 6782 |
useful building block for designing such classes.
|
| 6783 |
|
| 6784 |
-
[^
|
| 6785 |
-
|
| 6786 |
can be increased with the `resize` member function.
|
| 6787 |
|
| 6788 |
-
[^
|
| 6789 |
to a `valarray` object.
|
| 6790 |
|
| 6791 |
-
[^
|
| 6792 |
alias. Implementations in which arrays share storage are permitted,
|
| 6793 |
but they would need to implement a copy-on-reference mechanism to
|
| 6794 |
ensure that arrays are conceptually distinct.
|
| 6795 |
|
| 6796 |
-
[^
|
| 6797 |
-
|
| 6798 |
Duff, and Hammerling: *A set of Level 3 Basic Linear Algebra
|
| 6799 |
Subprograms*; Technical Report MCS-P1-0888, Argonne National
|
| 6800 |
Laboratory (USA), Mathematics and Computer Science Division, August,
|
| 6801 |
1988.
|
| 6802 |
|
| 6803 |
-
[^
|
| 6804 |
of argument values (a) if it is explicitly defined for that set of
|
| 6805 |
argument values, or (b) if its limiting value exists and does not
|
| 6806 |
depend on the direction of approach.
|
|
|
|
| 15 |
| Subclause | | Header |
|
| 16 |
| ------------------------ | ----------------------------------------------- | ---------------------- |
|
| 17 |
| [[numeric.requirements]] | Requirements | |
|
| 18 |
| [[cfenv]] | Floating-point environment | `<cfenv>` |
|
| 19 |
| [[complex.numbers]] | Complex numbers | `<complex>` |
|
|
|
|
| 20 |
| [[rand]] | Random number generation | `<random>` |
|
| 21 |
| [[numarray]] | Numeric arrays | `<valarray>` |
|
| 22 |
| [[c.math]] | Mathematical functions for floating-point types | `<cmath>`, `<cstdlib>` |
|
| 23 |
| [[numbers]] | Numbers | `<numbers>` |
|
| 24 |
|
|
|
|
| 97 |
under non-default mode settings. If the pragma is used to enable control
|
| 98 |
over the floating-point environment, this document does not specify the
|
| 99 |
effect on floating-point evaluation in constant
|
| 100 |
expressions. — *end note*]
|
| 101 |
|
| 102 |
+
See also: ISO C 7.6
|
| 103 |
+
|
| 104 |
+
### Threads <a id="cfenv.thread">[[cfenv.thread]]</a>
|
| 105 |
+
|
| 106 |
The floating-point environment has thread storage duration
|
| 107 |
[[basic.stc.thread]]. The initial state for a thread’s floating-point
|
| 108 |
environment is the state of the floating-point environment of the thread
|
| 109 |
that constructs the corresponding `thread` object
|
| 110 |
[[thread.thread.class]] or `jthread` object [[thread.jthread.class]] at
|
| 111 |
the time it constructed the object.
|
| 112 |
|
| 113 |
+
[*Note 1*: That is, the child thread gets the floating-point state of
|
| 114 |
the parent thread at the time of the child’s creation. — *end note*]
|
| 115 |
|
| 116 |
A separate floating-point environment is maintained for each thread.
|
| 117 |
Each function accesses the environment corresponding to its calling
|
| 118 |
thread.
|
| 119 |
|
|
|
|
|
|
|
| 120 |
## Complex numbers <a id="complex.numbers">[[complex.numbers]]</a>
|
| 121 |
|
| 122 |
+
### General <a id="complex.numbers.general">[[complex.numbers.general]]</a>
|
| 123 |
+
|
| 124 |
The header `<complex>` defines a class template, and numerous functions
|
| 125 |
for representing and manipulating complex numbers.
|
| 126 |
|
| 127 |
+
The effect of instantiating the template `complex` for any type that is
|
| 128 |
+
not a cv-unqualified floating-point type [[basic.fundamental]] is
|
| 129 |
+
unspecified. Specializations of `complex` for cv-unqualified
|
| 130 |
+
floating-point types are trivially-copyable literal types
|
| 131 |
+
[[term.literal.type]].
|
| 132 |
|
| 133 |
If the result of a function is not mathematically defined or not in the
|
| 134 |
range of representable values for its type, the behavior is undefined.
|
| 135 |
|
| 136 |
If `z` is an lvalue of type cv `complex<T>` then:
|
|
|
|
| 154 |
``` cpp
|
| 155 |
namespace std {
|
| 156 |
// [complex], class template complex
|
| 157 |
template<class T> class complex;
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
// [complex.ops], operators
|
| 160 |
template<class T> constexpr complex<T> operator+(const complex<T>&, const complex<T>&);
|
| 161 |
template<class T> constexpr complex<T> operator+(const complex<T>&, const T&);
|
| 162 |
template<class T> constexpr complex<T> operator+(const T&, const complex<T>&);
|
| 163 |
|
|
|
|
| 243 |
template<class T> class complex {
|
| 244 |
public:
|
| 245 |
using value_type = T;
|
| 246 |
|
| 247 |
constexpr complex(const T& re = T(), const T& im = T());
|
| 248 |
+
constexpr complex(const complex&) = default;
|
| 249 |
+
template<class X> constexpr explicit(see below) complex(const complex<X>&);
|
| 250 |
|
| 251 |
constexpr T real() const;
|
| 252 |
constexpr void real(T);
|
| 253 |
constexpr T imag() const;
|
| 254 |
constexpr void imag(T);
|
|
|
|
| 270 |
```
|
| 271 |
|
| 272 |
The class `complex` describes an object that can store the Cartesian
|
| 273 |
components, `real()` and `imag()`, of a complex number.
|
| 274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
### Member functions <a id="complex.members">[[complex.members]]</a>
|
| 276 |
|
| 277 |
``` cpp
|
| 278 |
+
constexpr complex(const T& re = T(), const T& im = T());
|
| 279 |
```
|
| 280 |
|
| 281 |
*Ensures:* `real() == re && imag() == im` is `true`.
|
| 282 |
|
| 283 |
+
``` cpp
|
| 284 |
+
template<class X> constexpr explicit(see below) complex(const complex<X>& other);
|
| 285 |
+
```
|
| 286 |
+
|
| 287 |
+
*Effects:* Initializes the real part with `other.real()` and the
|
| 288 |
+
imaginary part with `other.imag()`.
|
| 289 |
+
|
| 290 |
+
*Remarks:* The expression inside `explicit` evaluates to `false` if and
|
| 291 |
+
only if the floating-point conversion rank of `T` is greater than or
|
| 292 |
+
equal to the floating-point conversion rank of `X`.
|
| 293 |
+
|
| 294 |
``` cpp
|
| 295 |
constexpr T real() const;
|
| 296 |
```
|
| 297 |
|
| 298 |
*Returns:* The value of the real component.
|
|
|
|
| 478 |
``` cpp
|
| 479 |
basic_ostringstream<charT, traits> s;
|
| 480 |
s.flags(o.flags());
|
| 481 |
s.imbue(o.getloc());
|
| 482 |
s.precision(o.precision());
|
| 483 |
+
s << '(' << x.real() << ',' << x.imag() << ')';
|
| 484 |
return o << s.str();
|
| 485 |
```
|
| 486 |
|
| 487 |
[*Note 1*: In a locale in which comma is used as a decimal point
|
| 488 |
character, the use of comma as a field separator can be ambiguous.
|
|
|
|
| 701 |
|
| 702 |
where `norm`, `conj`, `imag`, and `real` are `constexpr` overloads.
|
| 703 |
|
| 704 |
The additional overloads shall be sufficient to ensure:
|
| 705 |
|
| 706 |
+
- If the argument has a floating-point type `T`, then it is effectively
|
| 707 |
+
cast to `complex<T>`.
|
| 708 |
+
- Otherwise, if the argument has integer type, then it is effectively
|
| 709 |
+
cast to `complex<double>`.
|
|
|
|
|
|
|
| 710 |
|
| 711 |
+
Function template `pow` has additional overloads sufficient to ensure,
|
| 712 |
+
for a call with one argument of type `complex<T1>` and the other
|
| 713 |
+
argument of type `T2` or `complex<T2>`, both arguments are effectively
|
| 714 |
+
cast to `complex<common_type_t<T1, T2>>`. If `common_type_t<T1, T2>` is
|
| 715 |
+
not well-formed, then the program is ill-formed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
|
| 717 |
### Suffixes for complex number literals <a id="complex.literals">[[complex.literals]]</a>
|
| 718 |
|
| 719 |
This subclause describes literal suffixes for constructing complex
|
| 720 |
number literals. The suffixes `i`, `il`, and `if` create complex numbers
|
|
|
|
| 741 |
constexpr complex<float> operator""if(unsigned long long d);
|
| 742 |
```
|
| 743 |
|
| 744 |
*Returns:* `complex<float>{0.0f, static_cast<float>(d)}`.
|
| 745 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
## Random number generation <a id="rand">[[rand]]</a>
|
| 747 |
|
| 748 |
+
### General <a id="rand.general">[[rand.general]]</a>
|
| 749 |
+
|
| 750 |
+
Subclause [[rand]] defines a facility for generating (pseudo-)random
|
| 751 |
numbers.
|
| 752 |
|
| 753 |
In addition to a few utilities, four categories of entities are
|
| 754 |
described: *uniform random bit generators*, *random number engines*,
|
| 755 |
*random number engine adaptors*, and *random number distributions*.
|
|
|
|
| 761 |
binding of any uniform random bit generator object `e` as the argument
|
| 762 |
to any random number distribution object `d`, thus producing a
|
| 763 |
zero-argument function object such as given by
|
| 764 |
`bind(d,e)`. — *end note*]
|
| 765 |
|
| 766 |
+
Each of the entities specified in [[rand]] has an associated arithmetic
|
| 767 |
+
type [[basic.fundamental]] identified as `result_type`. With `T` as the
|
| 768 |
+
`result_type` thus associated with such an entity, that entity is
|
| 769 |
+
characterized:
|
| 770 |
|
| 771 |
- as *boolean* or equivalently as *boolean-valued*, if `T` is `bool`;
|
| 772 |
- otherwise as *integral* or equivalently as *integer-valued*, if
|
| 773 |
`numeric_limits<T>::is_integer` is `true`;
|
| 774 |
- otherwise as *floating-point* or equivalently as *real-valued*.
|
| 775 |
|
| 776 |
If integer-valued, an entity may optionally be further characterized as
|
| 777 |
*signed* or *unsigned*, according to `numeric_limits<T>::is_signed`.
|
| 778 |
|
| 779 |
+
Unless otherwise specified, all descriptions of calculations in [[rand]]
|
| 780 |
+
use mathematical real numbers.
|
| 781 |
|
| 782 |
+
Throughout [[rand]], the operators , , and \xor denote the respective
|
| 783 |
+
conventional bitwise operations. Further:
|
| 784 |
|
| 785 |
- the operator \rightshift denotes a bitwise right shift with
|
| 786 |
zero-valued bits appearing in the high bits of the result, and
|
| 787 |
- the operator denotes a bitwise left shift with zero-valued bits
|
| 788 |
appearing in the low bits of the result, and whose result is always
|
| 789 |
taken modulo 2ʷ.
|
| 790 |
|
| 791 |
### Header `<random>` synopsis <a id="rand.synopsis">[[rand.synopsis]]</a>
|
| 792 |
|
| 793 |
``` cpp
|
| 794 |
+
#include <initializer_list> // see [initializer.list.syn]
|
| 795 |
|
| 796 |
namespace std {
|
| 797 |
// [rand.req.urng], uniform random bit generator requirements
|
| 798 |
template<class G>
|
| 799 |
concept uniform_random_bit_generator = see below;
|
|
|
|
| 982 |
semantics, and if `S` also meets all other requirements of this
|
| 983 |
subclause [[rand.req.seedseq]]. In that Table and throughout this
|
| 984 |
subclause:
|
| 985 |
|
| 986 |
- `T` is the type named by `S`’s associated `result_type`;
|
| 987 |
+
- `q` is a value of type `S` and `r` is a value of type `S` or
|
| 988 |
+
`const S`;
|
| 989 |
- `ib` and `ie` are input iterators with an unsigned integer
|
| 990 |
`value_type` of at least 32 bits;
|
| 991 |
- `rb` and `re` are mutable random access iterators with an unsigned
|
| 992 |
integer `value_type` of at least 32 bits;
|
| 993 |
- `ob` is an output iterator; and
|
| 994 |
+
- `il` is a value of type `initializer_list<T>`.
|
| 995 |
|
| 996 |
#### Uniform random bit generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
|
| 997 |
|
| 998 |
A *uniform random bit generator* `g` of type `G` is a function object
|
| 999 |
returning unsigned integer values such that each value in the range of
|
|
|
|
| 1054 |
requirements of this subclause [[rand.req.eng]]. In that Table and
|
| 1055 |
throughout this subclause:
|
| 1056 |
|
| 1057 |
- `T` is the type named by `E`’s associated `result_type`;
|
| 1058 |
- `e` is a value of `E`, `v` is an lvalue of `E`, `x` and `y` are
|
| 1059 |
+
(possibly const) values of `E`;
|
| 1060 |
- `s` is a value of `T`;
|
| 1061 |
- `q` is an lvalue meeting the requirements of a seed sequence
|
| 1062 |
[[rand.req.seedseq]];
|
| 1063 |
- `z` is a value of type `unsigned long long`;
|
| 1064 |
- `os` is an lvalue of the type of some class template specialization
|
| 1065 |
`basic_ostream<charT,` `traits>`; and
|
| 1066 |
- `is` is an lvalue of the type of some class template specialization
|
| 1067 |
`basic_istream<charT,` `traits>`;
|
| 1068 |
|
| 1069 |
where `charT` and `traits` are constrained according to [[strings]] and
|
| 1070 |
+
[[input.output]].[^2]
|
| 1071 |
|
| 1072 |
`E` shall meet the *Cpp17CopyConstructible* (
|
| 1073 |
[[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
|
| 1074 |
[[cpp17.copyassignable]]) requirements. These operations shall each be
|
| 1075 |
of complexity no worse than 𝑂(\text{size of state}).
|
|
|
|
| 1165 |
other requirements of this subclause [[rand.req.dist]]. In that Table
|
| 1166 |
and throughout this subclause,
|
| 1167 |
|
| 1168 |
- `T` is the type named by `D`’s associated `result_type`;
|
| 1169 |
- `P` is the type named by `D`’s associated `param_type`;
|
| 1170 |
+
- `d` is a value of `D`, and `x` and `y` are (possibly const) values of
|
| 1171 |
+
`D`;
|
| 1172 |
- `glb` and `lub` are values of `T` respectively corresponding to the
|
| 1173 |
greatest lower bound and the least upper bound on the values
|
| 1174 |
potentially returned by `d`’s `operator()`, as determined by the
|
| 1175 |
current values of `d`’s parameters;
|
| 1176 |
+
- `p` is a (possibly const) value of `P`;
|
| 1177 |
- `g`, `g1`, and `g2` are lvalues of a type meeting the requirements of
|
| 1178 |
a uniform random bit generator [[rand.req.urng]];
|
| 1179 |
- `os` is an lvalue of the type of some class template specialization
|
| 1180 |
`basic_ostream<charT,` `traits>`; and
|
| 1181 |
- `is` is an lvalue of the type of some class template specialization
|
|
|
|
| 1188 |
[[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
|
| 1189 |
[[cpp17.copyassignable]]) requirements.
|
| 1190 |
|
| 1191 |
The sequence of numbers produced by repeated invocations of `d(g)` shall
|
| 1192 |
be independent of any invocation of `os << d` or of any `const` member
|
| 1193 |
+
function of `D` between any of the invocations of `d(g)`.
|
| 1194 |
|
| 1195 |
If a textual representation is written using `os << x` and that
|
| 1196 |
representation is restored into the same or a different object `y` of
|
| 1197 |
the same type using `is >> y`, repeated invocations of `y(g)` shall
|
| 1198 |
produce the same sequence of numbers as would repeated invocations of
|
|
|
|
| 1222 |
using distribution_type = D;
|
| 1223 |
```
|
| 1224 |
|
| 1225 |
### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
|
| 1226 |
|
| 1227 |
+
#### General <a id="rand.eng.general">[[rand.eng.general]]</a>
|
| 1228 |
+
|
| 1229 |
+
Each type instantiated from a class template specified in [[rand.eng]]
|
| 1230 |
+
meets the requirements of a random number engine [[rand.req.eng]] type.
|
| 1231 |
|
| 1232 |
Except where specified otherwise, the complexity of each function
|
| 1233 |
+
specified in [[rand.eng]] is constant.
|
| 1234 |
|
| 1235 |
+
Except where specified otherwise, no function described in [[rand.eng]]
|
| 1236 |
+
throws an exception.
|
| 1237 |
|
| 1238 |
+
Every function described in [[rand.eng]] that has a function parameter
|
| 1239 |
+
`q` of type `Sseq&` for a template type parameter named `Sseq` that is
|
| 1240 |
+
different from type `seed_seq` throws what and when the invocation of
|
| 1241 |
+
`q.generate` throws.
|
| 1242 |
|
| 1243 |
+
Descriptions are provided in [[rand.eng]] only for engine operations
|
| 1244 |
+
that are not described in [[rand.req.eng]] or for operations where there
|
| 1245 |
+
is additional semantic information. In particular, declarations for copy
|
| 1246 |
+
constructors, for copy assignment operators, for streaming operators,
|
| 1247 |
+
and for equality and inequality operators are not shown in the synopses.
|
|
|
|
| 1248 |
|
| 1249 |
+
Each template specified in [[rand.eng]] requires one or more
|
| 1250 |
+
relationships, involving the value(s) of its non-type template
|
| 1251 |
parameter(s), to hold. A program instantiating any of these templates is
|
| 1252 |
ill-formed if any such required relationship fails to hold.
|
| 1253 |
|
| 1254 |
For every random number engine and for every random number engine
|
| 1255 |
+
adaptor `X` defined in [[rand.eng]] and in [[rand.adapt]]:
|
|
|
|
| 1256 |
|
| 1257 |
- if the constructor
|
| 1258 |
``` cpp
|
| 1259 |
template<class Sseq> explicit X(Sseq& q);
|
| 1260 |
```
|
|
|
|
| 1282 |
algorithm is a modular linear function of the form
|
| 1283 |
TA(xᵢ) = (a ⋅ xᵢ + c) mod m; the generation algorithm is
|
| 1284 |
GA(xᵢ) = xᵢ₊₁.
|
| 1285 |
|
| 1286 |
``` cpp
|
| 1287 |
+
namespace std {
|
| 1288 |
template<class UIntType, UIntType a, UIntType c, UIntType m>
|
| 1289 |
class linear_congruential_engine {
|
| 1290 |
public:
|
| 1291 |
// types
|
| 1292 |
using result_type = UIntType;
|
|
|
|
| 1304 |
explicit linear_congruential_engine(result_type s);
|
| 1305 |
template<class Sseq> explicit linear_congruential_engine(Sseq& q);
|
| 1306 |
void seed(result_type s = default_seed);
|
| 1307 |
template<class Sseq> void seed(Sseq& q);
|
| 1308 |
|
| 1309 |
+
// equality operators
|
| 1310 |
+
friend bool operator==(const linear_congruential_engine& x,
|
| 1311 |
+
const linear_congruential_engine& y);
|
| 1312 |
+
|
| 1313 |
// generating functions
|
| 1314 |
result_type operator()();
|
| 1315 |
void discard(unsigned long long z);
|
| 1316 |
+
|
| 1317 |
+
// inserters and extractors
|
| 1318 |
+
template<class charT, class traits>
|
| 1319 |
+
friend basic_ostream<charT, traits>&
|
| 1320 |
+
operator<<(basic_ostream<charT, traits>& os, const linear_congruential_engine& x);
|
| 1321 |
+
template<class charT, class traits>
|
| 1322 |
+
friend basic_istream<charT, traits>&
|
| 1323 |
+
operator>>(basic_istream<charT, traits>& is, linear_congruential_engine& x);
|
| 1324 |
};
|
| 1325 |
+
}
|
| 1326 |
```
|
| 1327 |
|
| 1328 |
If the template parameter `m` is 0, the modulus m used throughout this
|
| 1329 |
subclause [[rand.eng.lcong]] is `numeric_limits<result_type>::max()`
|
| 1330 |
plus 1.
|
|
|
|
| 1355 |
If c mod m is 0 and S is 0, sets the engine’s state to 1, else sets
|
| 1356 |
the engine’s state to S.
|
| 1357 |
|
| 1358 |
#### Class template `mersenne_twister_engine` <a id="rand.eng.mers">[[rand.eng.mers]]</a>
|
| 1359 |
|
| 1360 |
+
A `mersenne_twister_engine` random number engine[^3]
|
| 1361 |
+
|
| 1362 |
+
produces unsigned integer random numbers in the closed interval
|
| 1363 |
+
[0,2ʷ-1]. The state xᵢ of a `mersenne_twister_engine` object `x` is of
|
| 1364 |
+
size n and consists of a sequence X of n values of the type delivered by
|
| 1365 |
+
`x`; all subscripts applied to X are to be taken modulo n.
|
| 1366 |
|
| 1367 |
The transition algorithm employs a twisted generalized feedback shift
|
| 1368 |
register defined by shift values n and m, a twist value r, and a
|
| 1369 |
conditional xor-mask a. To improve the uniformity of the result, the
|
| 1370 |
bits of the raw shift register are additionally *tempered* (i.e.,
|
|
|
|
| 1388 |
- Let $z_2 = z_1 \xor \bigl( (z_1 \leftshift{w} s) \bitand b \bigr)$.
|
| 1389 |
- Let $z_3 = z_2 \xor \bigl( (z_2 \leftshift{w} t) \bitand c \bigr)$.
|
| 1390 |
- Let $z_4 = z_3 \xor ( z_3 \rightshift \ell )$.
|
| 1391 |
|
| 1392 |
``` cpp
|
| 1393 |
+
namespace std {
|
| 1394 |
template<class UIntType, size_t w, size_t n, size_t m, size_t r,
|
| 1395 |
UIntType a, size_t u, UIntType d, size_t s,
|
| 1396 |
UIntType b, size_t t,
|
| 1397 |
UIntType c, size_t l, UIntType f>
|
| 1398 |
class mersenne_twister_engine {
|
|
|
|
| 1423 |
explicit mersenne_twister_engine(result_type value);
|
| 1424 |
template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
|
| 1425 |
void seed(result_type value = default_seed);
|
| 1426 |
template<class Sseq> void seed(Sseq& q);
|
| 1427 |
|
| 1428 |
+
// equality operators
|
| 1429 |
+
friend bool operator==(const mersenne_twister_engine& x, const mersenne_twister_engine& y);
|
| 1430 |
+
|
| 1431 |
// generating functions
|
| 1432 |
result_type operator()();
|
| 1433 |
void discard(unsigned long long z);
|
| 1434 |
+
|
| 1435 |
+
// inserters and extractors
|
| 1436 |
+
template<class charT, class traits>
|
| 1437 |
+
friend basic_ostream<charT, traits>&
|
| 1438 |
+
operator<<(basic_ostream<charT, traits>& os, const mersenne_twister_engine& x);
|
| 1439 |
+
template<class charT, class traits>
|
| 1440 |
+
friend basic_istream<charT, traits>&
|
| 1441 |
+
operator>>(basic_istream<charT, traits>& is, mersenne_twister_engine& x);
|
| 1442 |
};
|
| 1443 |
+
}
|
| 1444 |
```
|
| 1445 |
|
| 1446 |
The following relations shall hold: `0 < m`, `m <= n`, `2u < w`,
|
| 1447 |
`r <= w`, `u <= w`, `s <= w`, `t <= w`, `l <= w`,
|
| 1448 |
`w <= numeric_limits<UIntType>::digits`, `a <= (1u<<w) - 1u`,
|
|
|
|
| 1500 |
|
| 1501 |
The generation algorithm is given by GA(xᵢ) = y, where y is the value
|
| 1502 |
produced as a result of advancing the engine’s state as described above.
|
| 1503 |
|
| 1504 |
``` cpp
|
| 1505 |
+
namespace std {
|
| 1506 |
template<class UIntType, size_t w, size_t s, size_t r>
|
| 1507 |
class subtract_with_carry_engine {
|
| 1508 |
public:
|
| 1509 |
// types
|
| 1510 |
using result_type = UIntType;
|
|
|
|
| 1522 |
explicit subtract_with_carry_engine(result_type value);
|
| 1523 |
template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
|
| 1524 |
void seed(result_type value = default_seed);
|
| 1525 |
template<class Sseq> void seed(Sseq& q);
|
| 1526 |
|
| 1527 |
+
// equality operators
|
| 1528 |
+
friend bool operator==(const subtract_with_carry_engine& x,
|
| 1529 |
+
const subtract_with_carry_engine& y);
|
| 1530 |
+
|
| 1531 |
// generating functions
|
| 1532 |
result_type operator()();
|
| 1533 |
void discard(unsigned long long z);
|
| 1534 |
+
|
| 1535 |
+
// inserters and extractors
|
| 1536 |
+
template<class charT, class traits>
|
| 1537 |
+
friend basic_ostream<charT, traits>&
|
| 1538 |
+
operator<<(basic_ostream<charT, traits>& os, const subtract_with_carry_engine& x);
|
| 1539 |
+
template<class charT, class traits>
|
| 1540 |
+
friend basic_istream<charT, traits>&
|
| 1541 |
+
operator>>(basic_istream<charT, traits>& is, subtract_with_carry_engine& x);
|
| 1542 |
};
|
| 1543 |
+
}
|
| 1544 |
```
|
| 1545 |
|
| 1546 |
The following relations shall hold: `0u < s`, `s < r`, `0 < w`, and
|
| 1547 |
`w <= numeric_limits<UIntType>::digits`.
|
| 1548 |
|
|
|
|
| 1563 |
linear_congruential_engine<result_type,
|
| 1564 |
40014u,0u,2147483563u> e(value == 0u ? default_seed : value);
|
| 1565 |
```
|
| 1566 |
|
| 1567 |
Then, to set each Xₖ, obtain new values z₀, …, zₙ₋₁ from n = ⌈ w/32 ⌉
|
| 1568 |
+
successive invocations of `e`. Set Xₖ to
|
| 1569 |
$\left( \sum_{j=0}^{n-1} z_j \cdot 2^{32j}\right) \bmod m$.
|
| 1570 |
|
| 1571 |
*Complexity:* Exactly n ⋅ `r` invocations of `e`.
|
| 1572 |
|
| 1573 |
``` cpp
|
|
|
|
| 1627 |
|
| 1628 |
The generation algorithm yields the value returned by the last
|
| 1629 |
invocation of `e()` while advancing `e`’s state as described above.
|
| 1630 |
|
| 1631 |
``` cpp
|
| 1632 |
+
namespace std {
|
| 1633 |
template<class Engine, size_t p, size_t r>
|
| 1634 |
class discard_block_engine {
|
| 1635 |
public:
|
| 1636 |
// types
|
| 1637 |
using result_type = typename Engine::result_type;
|
|
|
|
| 1650 |
template<class Sseq> explicit discard_block_engine(Sseq& q);
|
| 1651 |
void seed();
|
| 1652 |
void seed(result_type s);
|
| 1653 |
template<class Sseq> void seed(Sseq& q);
|
| 1654 |
|
| 1655 |
+
// equality operators
|
| 1656 |
+
friend bool operator==(const discard_block_engine& x, const discard_block_engine& y);
|
| 1657 |
+
|
| 1658 |
// generating functions
|
| 1659 |
result_type operator()();
|
| 1660 |
void discard(unsigned long long z);
|
| 1661 |
|
| 1662 |
// property functions
|
| 1663 |
+
const Engine& base() const noexcept { return e; }
|
| 1664 |
+
|
| 1665 |
+
// inserters and extractors
|
| 1666 |
+
template<class charT, class traits>
|
| 1667 |
+
friend basic_ostream<charT, traits>&
|
| 1668 |
+
operator<<(basic_ostream<charT, traits>& os, const discard_block_engine& x);
|
| 1669 |
+
template<class charT, class traits>
|
| 1670 |
+
friend basic_istream<charT, traits>&
|
| 1671 |
+
operator>>(basic_istream<charT, traits>& is, discard_block_engine& x);
|
| 1672 |
|
| 1673 |
private:
|
| 1674 |
Engine e; // exposition only
|
| 1675 |
+
size_t n; // exposition only
|
| 1676 |
};
|
| 1677 |
+
}
|
| 1678 |
```
|
| 1679 |
|
| 1680 |
The following relations shall hold: `0 < r` and `r <= p`.
|
| 1681 |
|
| 1682 |
The textual representation consists of the textual representation of `e`
|
|
|
|
| 1746 |
template<class Sseq> explicit independent_bits_engine(Sseq& q);
|
| 1747 |
void seed();
|
| 1748 |
void seed(result_type s);
|
| 1749 |
template<class Sseq> void seed(Sseq& q);
|
| 1750 |
|
| 1751 |
+
// equality operators
|
| 1752 |
+
friend bool operator==(const independent_bits_engine& x, const independent_bits_engine& y);
|
| 1753 |
+
|
| 1754 |
// generating functions
|
| 1755 |
result_type operator()();
|
| 1756 |
void discard(unsigned long long z);
|
| 1757 |
|
| 1758 |
// property functions
|
| 1759 |
+
const Engine& base() const noexcept { return e; }
|
| 1760 |
+
|
| 1761 |
+
// inserters and extractors
|
| 1762 |
+
template<class charT, class traits>
|
| 1763 |
+
friend basic_ostream<charT, traits>&
|
| 1764 |
+
operator<<(basic_ostream<charT, traits>& os, const independent_bits_engine& x);
|
| 1765 |
+
template<class charT, class traits>
|
| 1766 |
+
friend basic_istream<charT, traits>&
|
| 1767 |
+
operator>>(basic_istream<charT, traits>& is, independent_bits_engine& x);
|
| 1768 |
|
| 1769 |
private:
|
| 1770 |
Engine e; // exposition only
|
| 1771 |
};
|
| 1772 |
```
|
|
|
|
| 1797 |
|
| 1798 |
The generation algorithm yields the last value of `Y` produced while
|
| 1799 |
advancing `e`’s state as described above.
|
| 1800 |
|
| 1801 |
``` cpp
|
| 1802 |
+
namespace std {
|
| 1803 |
template<class Engine, size_t k>
|
| 1804 |
class shuffle_order_engine {
|
| 1805 |
public:
|
| 1806 |
// types
|
| 1807 |
using result_type = typename Engine::result_type;
|
|
|
|
| 1819 |
template<class Sseq> explicit shuffle_order_engine(Sseq& q);
|
| 1820 |
void seed();
|
| 1821 |
void seed(result_type s);
|
| 1822 |
template<class Sseq> void seed(Sseq& q);
|
| 1823 |
|
| 1824 |
+
// equality operators
|
| 1825 |
+
friend bool operator==(const shuffle_order_engine& x, const shuffle_order_engine& y);
|
| 1826 |
+
|
| 1827 |
// generating functions
|
| 1828 |
result_type operator()();
|
| 1829 |
void discard(unsigned long long z);
|
| 1830 |
|
| 1831 |
// property functions
|
| 1832 |
+
const Engine& base() const noexcept { return e; }
|
| 1833 |
+
|
| 1834 |
+
// inserters and extractors
|
| 1835 |
+
template<class charT, class traits>
|
| 1836 |
+
friend basic_ostream<charT, traits>&
|
| 1837 |
+
operator<<(basic_ostream<charT, traits>& os, const shuffle_order_engine& x);
|
| 1838 |
+
template<class charT, class traits>
|
| 1839 |
+
friend basic_istream<charT, traits>&
|
| 1840 |
+
operator>>(basic_istream<charT, traits>& is, shuffle_order_engine& x);
|
| 1841 |
|
| 1842 |
private:
|
| 1843 |
Engine e; // exposition only
|
| 1844 |
result_type V[k]; // exposition only
|
| 1845 |
result_type Y; // exposition only
|
| 1846 |
};
|
| 1847 |
+
}
|
| 1848 |
```
|
| 1849 |
|
| 1850 |
The following relation shall hold: `0 < k`.
|
| 1851 |
|
| 1852 |
The textual representation consists of the textual representation of
|
|
|
|
| 1945 |
```
|
| 1946 |
|
| 1947 |
*Remarks:* The choice of engine type named by this `typedef` is
|
| 1948 |
*implementation-defined*.
|
| 1949 |
|
| 1950 |
+
[*Note 1*: The implementation can select this type on the basis of
|
| 1951 |
performance, size, quality, or any combination of such factors, so as to
|
| 1952 |
provide at least acceptable engine behavior for relatively casual,
|
| 1953 |
+
inexpert, and/or lightweight use. Because different implementations can
|
| 1954 |
select different underlying engine types, code that uses this `typedef`
|
| 1955 |
need not generate identical sequences across
|
| 1956 |
implementations. — *end note*]
|
| 1957 |
|
| 1958 |
### Class `random_device` <a id="rand.device">[[rand.device]]</a>
|
|
|
|
| 1962 |
|
| 1963 |
If implementation limitations prevent generating nondeterministic random
|
| 1964 |
numbers, the implementation may employ a random number engine.
|
| 1965 |
|
| 1966 |
``` cpp
|
| 1967 |
+
namespace std {
|
| 1968 |
class random_device {
|
| 1969 |
public:
|
| 1970 |
// types
|
| 1971 |
using result_type = unsigned int;
|
| 1972 |
|
|
|
|
| 1986 |
|
| 1987 |
// no copy functions
|
| 1988 |
random_device(const random_device&) = delete;
|
| 1989 |
void operator=(const random_device&) = delete;
|
| 1990 |
};
|
| 1991 |
+
}
|
| 1992 |
```
|
| 1993 |
|
| 1994 |
``` cpp
|
| 1995 |
explicit random_device(const string& token);
|
| 1996 |
```
|
| 1997 |
|
| 1998 |
+
*Throws:* A value of an *implementation-defined* type derived from
|
| 1999 |
+
`exception` if the `random_device` cannot be initialized.
|
| 2000 |
+
|
| 2001 |
*Remarks:* The semantics of the `token` parameter and the token value
|
| 2002 |
+
used by the default constructor are *implementation-defined*.[^4]
|
|
|
|
|
|
|
|
|
|
| 2003 |
|
| 2004 |
``` cpp
|
| 2005 |
double entropy() const noexcept;
|
| 2006 |
```
|
| 2007 |
|
| 2008 |
*Returns:* If the implementation employs a random number engine, returns
|
| 2009 |
+
0.0. Otherwise, returns an entropy estimate[^5]
|
| 2010 |
+
|
| 2011 |
+
for the random numbers returned by `operator()`, in the range `min()` to
|
| 2012 |
+
log₂( `max()`+1).
|
| 2013 |
|
| 2014 |
``` cpp
|
| 2015 |
result_type operator()();
|
| 2016 |
```
|
| 2017 |
|
| 2018 |
*Returns:* A nondeterministic random value, uniformly distributed
|
| 2019 |
between `min()` and `max()` (inclusive). It is *implementation-defined*
|
| 2020 |
how these values are generated.
|
| 2021 |
|
| 2022 |
*Throws:* A value of an *implementation-defined* type derived from
|
| 2023 |
+
`exception` if a random number cannot be obtained.
|
| 2024 |
|
| 2025 |
### Utilities <a id="rand.util">[[rand.util]]</a>
|
| 2026 |
|
| 2027 |
#### Class `seed_seq` <a id="rand.util.seedseq">[[rand.util.seedseq]]</a>
|
| 2028 |
|
| 2029 |
``` cpp
|
| 2030 |
+
namespace std {
|
| 2031 |
class seed_seq {
|
| 2032 |
public:
|
| 2033 |
// types
|
| 2034 |
using result_type = uint_least32_t;
|
| 2035 |
|
| 2036 |
// constructors
|
| 2037 |
+
seed_seq() noexcept;
|
| 2038 |
template<class T>
|
| 2039 |
seed_seq(initializer_list<T> il);
|
| 2040 |
template<class InputIterator>
|
| 2041 |
seed_seq(InputIterator begin, InputIterator end);
|
| 2042 |
|
|
|
|
| 2054 |
void operator=(const seed_seq&) = delete;
|
| 2055 |
|
| 2056 |
private:
|
| 2057 |
vector<result_type> v; // exposition only
|
| 2058 |
};
|
| 2059 |
+
}
|
| 2060 |
```
|
| 2061 |
|
| 2062 |
``` cpp
|
| 2063 |
+
seed_seq() noexcept;
|
| 2064 |
```
|
| 2065 |
|
| 2066 |
*Ensures:* `v.empty()` is `true`.
|
| 2067 |
|
|
|
|
|
|
|
| 2068 |
``` cpp
|
| 2069 |
template<class T>
|
| 2070 |
seed_seq(initializer_list<T> il);
|
| 2071 |
```
|
| 2072 |
|
| 2073 |
+
*Constraints:* `T` is an integer type.
|
| 2074 |
|
| 2075 |
*Effects:* Same as `seed_seq(il.begin(), il.end())`.
|
| 2076 |
|
| 2077 |
``` cpp
|
| 2078 |
template<class InputIterator>
|
|
|
|
| 2188 |
``` cpp
|
| 2189 |
template<class RealType, size_t bits, class URBG>
|
| 2190 |
RealType generate_canonical(URBG& g);
|
| 2191 |
```
|
| 2192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2193 |
*Effects:* Invokes `g()` k times to obtain values g₀, …, gₖ₋₁,
|
| 2194 |
respectively. Calculates a quantity
|
| 2195 |
$$S = \sum_{i=0}^{k-1} (g_i - \texttt{g.min()})
|
| 2196 |
\cdot R^i$$ using arithmetic of type `RealType`.
|
| 2197 |
|
|
|
|
| 2199 |
|
| 2200 |
[*Note 1*: 0 ≤ S / Rᵏ < 1. — *end note*]
|
| 2201 |
|
| 2202 |
*Throws:* What and when `g` throws.
|
| 2203 |
|
| 2204 |
+
*Complexity:* Exactly k = max(1, ⌈ b / log₂ R ⌉) invocations of `g`,
|
| 2205 |
+
where b[^6]
|
| 2206 |
+
|
| 2207 |
+
is the lesser of `numeric_limits<RealType>::digits` and `bits`, and R is
|
| 2208 |
+
the value of `g.max()` - `g.min()` + 1.
|
| 2209 |
+
|
| 2210 |
[*Note 2*: If the values gᵢ produced by `g` are uniformly distributed,
|
| 2211 |
the instantiation’s results are distributed as uniformly as possible.
|
| 2212 |
Obtaining a value in this way can be a useful step in the process of
|
| 2213 |
transforming a value generated by a uniform random bit generator into a
|
| 2214 |
value that can be delivered by a random number
|
|
|
|
| 2243 |
A `uniform_int_distribution` random number distribution produces random
|
| 2244 |
integers i, a ≤ i ≤ b, distributed according to the constant discrete
|
| 2245 |
probability function $$P(i\,|\,a,b) = 1 / (b - a + 1) \text{ .}$$
|
| 2246 |
|
| 2247 |
``` cpp
|
| 2248 |
+
namespace std {
|
| 2249 |
template<class IntType = int>
|
| 2250 |
class uniform_int_distribution {
|
| 2251 |
public:
|
| 2252 |
// types
|
| 2253 |
using result_type = IntType;
|
|
|
|
| 2257 |
uniform_int_distribution() : uniform_int_distribution(0) {}
|
| 2258 |
explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
|
| 2259 |
explicit uniform_int_distribution(const param_type& parm);
|
| 2260 |
void reset();
|
| 2261 |
|
| 2262 |
+
// equality operators
|
| 2263 |
+
friend bool operator==(const uniform_int_distribution& x, const uniform_int_distribution& y);
|
| 2264 |
+
|
| 2265 |
// generating functions
|
| 2266 |
template<class URBG>
|
| 2267 |
result_type operator()(URBG& g);
|
| 2268 |
template<class URBG>
|
| 2269 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2273 |
result_type b() const;
|
| 2274 |
param_type param() const;
|
| 2275 |
void param(const param_type& parm);
|
| 2276 |
result_type min() const;
|
| 2277 |
result_type max() const;
|
| 2278 |
+
|
| 2279 |
+
// inserters and extractors
|
| 2280 |
+
template<class charT, class traits>
|
| 2281 |
+
friend basic_ostream<charT, traits>&
|
| 2282 |
+
operator<<(basic_ostream<charT, traits>& os, const uniform_int_distribution& x);
|
| 2283 |
+
template<class charT, class traits>
|
| 2284 |
+
friend basic_istream<charT, traits>&
|
| 2285 |
+
operator>>(basic_istream<charT, traits>& is, uniform_int_distribution& x);
|
| 2286 |
};
|
| 2287 |
+
}
|
| 2288 |
```
|
| 2289 |
|
| 2290 |
``` cpp
|
| 2291 |
explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());
|
| 2292 |
```
|
|
|
|
| 2318 |
|
| 2319 |
[*Note 1*: This implies that p(x | a,b) is undefined when
|
| 2320 |
`a == b`. — *end note*]
|
| 2321 |
|
| 2322 |
``` cpp
|
| 2323 |
+
namespace std {
|
| 2324 |
template<class RealType = double>
|
| 2325 |
class uniform_real_distribution {
|
| 2326 |
public:
|
| 2327 |
// types
|
| 2328 |
using result_type = RealType;
|
|
|
|
| 2332 |
uniform_real_distribution() : uniform_real_distribution(0.0) {}
|
| 2333 |
explicit uniform_real_distribution(RealType a, RealType b = 1.0);
|
| 2334 |
explicit uniform_real_distribution(const param_type& parm);
|
| 2335 |
void reset();
|
| 2336 |
|
| 2337 |
+
// equality operators
|
| 2338 |
+
friend bool operator==(const uniform_real_distribution& x,
|
| 2339 |
+
const uniform_real_distribution& y);
|
| 2340 |
+
|
| 2341 |
// generating functions
|
| 2342 |
template<class URBG>
|
| 2343 |
result_type operator()(URBG& g);
|
| 2344 |
template<class URBG>
|
| 2345 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2349 |
result_type b() const;
|
| 2350 |
param_type param() const;
|
| 2351 |
void param(const param_type& parm);
|
| 2352 |
result_type min() const;
|
| 2353 |
result_type max() const;
|
| 2354 |
+
|
| 2355 |
+
// inserters and extractors
|
| 2356 |
+
template<class charT, class traits>
|
| 2357 |
+
friend basic_ostream<charT, traits>&
|
| 2358 |
+
operator<<(basic_ostream<charT, traits>& os, const uniform_real_distribution& x);
|
| 2359 |
+
template<class charT, class traits>
|
| 2360 |
+
friend basic_istream<charT, traits>&
|
| 2361 |
+
operator>>(basic_istream<charT, traits>& is, uniform_real_distribution& x);
|
| 2362 |
};
|
| 2363 |
+
}
|
| 2364 |
```
|
| 2365 |
|
| 2366 |
``` cpp
|
| 2367 |
explicit uniform_real_distribution(RealType a, RealType b = 1.0);
|
| 2368 |
```
|
|
|
|
| 2397 |
p & \text{ if $b = \tcode{true}$, or} \\
|
| 2398 |
1 - p & \text{ if $b = \tcode{false}$.}
|
| 2399 |
\end{array}\right.$$
|
| 2400 |
|
| 2401 |
``` cpp
|
| 2402 |
+
namespace std {
|
| 2403 |
class bernoulli_distribution {
|
| 2404 |
public:
|
| 2405 |
// types
|
| 2406 |
using result_type = bool;
|
| 2407 |
using param_type = unspecified;
|
|
|
|
| 2410 |
bernoulli_distribution() : bernoulli_distribution(0.5) {}
|
| 2411 |
explicit bernoulli_distribution(double p);
|
| 2412 |
explicit bernoulli_distribution(const param_type& parm);
|
| 2413 |
void reset();
|
| 2414 |
|
| 2415 |
+
// equality operators
|
| 2416 |
+
friend bool operator==(const bernoulli_distribution& x, const bernoulli_distribution& y);
|
| 2417 |
+
|
| 2418 |
// generating functions
|
| 2419 |
template<class URBG>
|
| 2420 |
result_type operator()(URBG& g);
|
| 2421 |
template<class URBG>
|
| 2422 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2425 |
double p() const;
|
| 2426 |
param_type param() const;
|
| 2427 |
void param(const param_type& parm);
|
| 2428 |
result_type min() const;
|
| 2429 |
result_type max() const;
|
| 2430 |
+
|
| 2431 |
+
// inserters and extractors
|
| 2432 |
+
template<class charT, class traits>
|
| 2433 |
+
friend basic_ostream<charT, traits>&
|
| 2434 |
+
operator<<(basic_ostream<charT, traits>& os, const bernoulli_distribution& x);
|
| 2435 |
+
template<class charT, class traits>
|
| 2436 |
+
friend basic_istream<charT, traits>&
|
| 2437 |
+
operator>>(basic_istream<charT, traits>& is, bernoulli_distribution& x);
|
| 2438 |
};
|
| 2439 |
+
}
|
| 2440 |
```
|
| 2441 |
|
| 2442 |
``` cpp
|
| 2443 |
explicit bernoulli_distribution(double p);
|
| 2444 |
```
|
|
|
|
| 2459 |
A `binomial_distribution` random number distribution produces integer
|
| 2460 |
values i ≥ 0 distributed according to the discrete probability function
|
| 2461 |
$$P(i\,|\,t,p) = \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i} \text{ .}$$
|
| 2462 |
|
| 2463 |
``` cpp
|
| 2464 |
+
namespace std {
|
| 2465 |
template<class IntType = int>
|
| 2466 |
class binomial_distribution {
|
| 2467 |
public:
|
| 2468 |
// types
|
| 2469 |
using result_type = IntType;
|
|
|
|
| 2473 |
binomial_distribution() : binomial_distribution(1) {}
|
| 2474 |
explicit binomial_distribution(IntType t, double p = 0.5);
|
| 2475 |
explicit binomial_distribution(const param_type& parm);
|
| 2476 |
void reset();
|
| 2477 |
|
| 2478 |
+
// equality operators
|
| 2479 |
+
friend bool operator==(const binomial_distribution& x, const binomial_distribution& y);
|
| 2480 |
+
|
| 2481 |
// generating functions
|
| 2482 |
template<class URBG>
|
| 2483 |
result_type operator()(URBG& g);
|
| 2484 |
template<class URBG>
|
| 2485 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2489 |
double p() const;
|
| 2490 |
param_type param() const;
|
| 2491 |
void param(const param_type& parm);
|
| 2492 |
result_type min() const;
|
| 2493 |
result_type max() const;
|
| 2494 |
+
|
| 2495 |
+
// inserters and extractors
|
| 2496 |
+
template<class charT, class traits>
|
| 2497 |
+
friend basic_ostream<charT, traits>&
|
| 2498 |
+
operator<<(basic_ostream<charT, traits>& os, const binomial_distribution& x);
|
| 2499 |
+
template<class charT, class traits>
|
| 2500 |
+
friend basic_istream<charT, traits>&
|
| 2501 |
+
operator>>(basic_istream<charT, traits>& is, binomial_distribution& x);
|
| 2502 |
};
|
| 2503 |
+
}
|
| 2504 |
```
|
| 2505 |
|
| 2506 |
``` cpp
|
| 2507 |
explicit binomial_distribution(IntType t, double p = 0.5);
|
| 2508 |
```
|
|
|
|
| 2531 |
A `geometric_distribution` random number distribution produces integer
|
| 2532 |
values i ≥ 0 distributed according to the discrete probability function
|
| 2533 |
$$P(i\,|\,p) = p \cdot (1-p)^{i} \text{ .}$$
|
| 2534 |
|
| 2535 |
``` cpp
|
| 2536 |
+
namespace std {
|
| 2537 |
template<class IntType = int>
|
| 2538 |
class geometric_distribution {
|
| 2539 |
public:
|
| 2540 |
// types
|
| 2541 |
using result_type = IntType;
|
|
|
|
| 2545 |
geometric_distribution() : geometric_distribution(0.5) {}
|
| 2546 |
explicit geometric_distribution(double p);
|
| 2547 |
explicit geometric_distribution(const param_type& parm);
|
| 2548 |
void reset();
|
| 2549 |
|
| 2550 |
+
// equality operators
|
| 2551 |
+
friend bool operator==(const geometric_distribution& x, const geometric_distribution& y);
|
| 2552 |
+
|
| 2553 |
// generating functions
|
| 2554 |
template<class URBG>
|
| 2555 |
result_type operator()(URBG& g);
|
| 2556 |
template<class URBG>
|
| 2557 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2560 |
double p() const;
|
| 2561 |
param_type param() const;
|
| 2562 |
void param(const param_type& parm);
|
| 2563 |
result_type min() const;
|
| 2564 |
result_type max() const;
|
| 2565 |
+
|
| 2566 |
+
// inserters and extractors
|
| 2567 |
+
template<class charT, class traits>
|
| 2568 |
+
friend basic_ostream<charT, traits>&
|
| 2569 |
+
operator<<(basic_ostream<charT, traits>& os, const geometric_distribution& x);
|
| 2570 |
+
template<class charT, class traits>
|
| 2571 |
+
friend basic_istream<charT, traits>&
|
| 2572 |
+
operator>>(basic_istream<charT, traits>& is, geometric_distribution& x);
|
| 2573 |
};
|
| 2574 |
+
}
|
| 2575 |
```
|
| 2576 |
|
| 2577 |
``` cpp
|
| 2578 |
explicit geometric_distribution(double p);
|
| 2579 |
```
|
|
|
|
| 2598 |
|
| 2599 |
[*Note 1*: This implies that P(i | k,p) is undefined when
|
| 2600 |
`p == 1`. — *end note*]
|
| 2601 |
|
| 2602 |
``` cpp
|
| 2603 |
+
namespace std {
|
| 2604 |
template<class IntType = int>
|
| 2605 |
class negative_binomial_distribution {
|
| 2606 |
public:
|
| 2607 |
// types
|
| 2608 |
using result_type = IntType;
|
|
|
|
| 2612 |
negative_binomial_distribution() : negative_binomial_distribution(1) {}
|
| 2613 |
explicit negative_binomial_distribution(IntType k, double p = 0.5);
|
| 2614 |
explicit negative_binomial_distribution(const param_type& parm);
|
| 2615 |
void reset();
|
| 2616 |
|
| 2617 |
+
// equality operators
|
| 2618 |
+
friend bool operator==(const negative_binomial_distribution& x,
|
| 2619 |
+
const negative_binomial_distribution& y);
|
| 2620 |
+
|
| 2621 |
// generating functions
|
| 2622 |
template<class URBG>
|
| 2623 |
result_type operator()(URBG& g);
|
| 2624 |
template<class URBG>
|
| 2625 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2629 |
double p() const;
|
| 2630 |
param_type param() const;
|
| 2631 |
void param(const param_type& parm);
|
| 2632 |
result_type min() const;
|
| 2633 |
result_type max() const;
|
| 2634 |
+
|
| 2635 |
+
// inserters and extractors
|
| 2636 |
+
template<class charT, class traits>
|
| 2637 |
+
friend basic_ostream<charT, traits>&
|
| 2638 |
+
operator<<(basic_ostream<charT, traits>& os, const negative_binomial_distribution& x);
|
| 2639 |
+
template<class charT, class traits>
|
| 2640 |
+
friend basic_istream<charT, traits>&
|
| 2641 |
+
operator>>(basic_istream<charT, traits>& is, negative_binomial_distribution& x);
|
| 2642 |
};
|
| 2643 |
+
}
|
| 2644 |
```
|
| 2645 |
|
| 2646 |
``` cpp
|
| 2647 |
explicit negative_binomial_distribution(IntType k, double p = 0.5);
|
| 2648 |
```
|
|
|
|
| 2688 |
poisson_distribution() : poisson_distribution(1.0) {}
|
| 2689 |
explicit poisson_distribution(double mean);
|
| 2690 |
explicit poisson_distribution(const param_type& parm);
|
| 2691 |
void reset();
|
| 2692 |
|
| 2693 |
+
// equality operators
|
| 2694 |
+
friend bool operator==(const poisson_distribution& x, const poisson_distribution& y);
|
| 2695 |
+
|
| 2696 |
// generating functions
|
| 2697 |
template<class URBG>
|
| 2698 |
result_type operator()(URBG& g);
|
| 2699 |
template<class URBG>
|
| 2700 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2703 |
double mean() const;
|
| 2704 |
param_type param() const;
|
| 2705 |
void param(const param_type& parm);
|
| 2706 |
result_type min() const;
|
| 2707 |
result_type max() const;
|
| 2708 |
+
|
| 2709 |
+
// inserters and extractors
|
| 2710 |
+
template<class charT, class traits>
|
| 2711 |
+
friend basic_ostream<charT, traits>&
|
| 2712 |
+
operator<<(basic_ostream<charT, traits>& os, const poisson_distribution& x);
|
| 2713 |
+
template<class charT, class traits>
|
| 2714 |
+
friend basic_istream<charT, traits>&
|
| 2715 |
+
operator>>(basic_istream<charT, traits>& is, poisson_distribution& x);
|
| 2716 |
};
|
| 2717 |
```
|
| 2718 |
|
| 2719 |
``` cpp
|
| 2720 |
explicit poisson_distribution(double mean);
|
|
|
|
| 2736 |
An `exponential_distribution` random number distribution produces random
|
| 2737 |
numbers x > 0 distributed according to the probability density function
|
| 2738 |
$$p(x\,|\,\lambda) = \lambda e^{-\lambda x} \text{ .}$$
|
| 2739 |
|
| 2740 |
``` cpp
|
| 2741 |
+
namespace std {
|
| 2742 |
template<class RealType = double>
|
| 2743 |
class exponential_distribution {
|
| 2744 |
public:
|
| 2745 |
// types
|
| 2746 |
using result_type = RealType;
|
|
|
|
| 2750 |
exponential_distribution() : exponential_distribution(1.0) {}
|
| 2751 |
explicit exponential_distribution(RealType lambda);
|
| 2752 |
explicit exponential_distribution(const param_type& parm);
|
| 2753 |
void reset();
|
| 2754 |
|
| 2755 |
+
// equality operators
|
| 2756 |
+
friend bool operator==(const exponential_distribution& x, const exponential_distribution& y);
|
| 2757 |
+
|
| 2758 |
// generating functions
|
| 2759 |
template<class URBG>
|
| 2760 |
result_type operator()(URBG& g);
|
| 2761 |
template<class URBG>
|
| 2762 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2765 |
RealType lambda() const;
|
| 2766 |
param_type param() const;
|
| 2767 |
void param(const param_type& parm);
|
| 2768 |
result_type min() const;
|
| 2769 |
result_type max() const;
|
| 2770 |
+
|
| 2771 |
+
// inserters and extractors
|
| 2772 |
+
template<class charT, class traits>
|
| 2773 |
+
friend basic_ostream<charT, traits>&
|
| 2774 |
+
operator<<(basic_ostream<charT, traits>& os, const exponential_distribution& x);
|
| 2775 |
+
template<class charT, class traits>
|
| 2776 |
+
friend basic_istream<charT, traits>&
|
| 2777 |
+
operator>>(basic_istream<charT, traits>& is, exponential_distribution& x);
|
| 2778 |
};
|
| 2779 |
+
}
|
| 2780 |
```
|
| 2781 |
|
| 2782 |
``` cpp
|
| 2783 |
explicit exponential_distribution(RealType lambda);
|
| 2784 |
```
|
|
|
|
| 2801 |
$$p(x\,|\,\alpha,\beta) =
|
| 2802 |
\frac{e^{-x/\beta}}{\beta^{\alpha} \cdot \Gamma(\alpha)} \, \cdot \, x^{\, \alpha-1}
|
| 2803 |
\text{ .}$$
|
| 2804 |
|
| 2805 |
``` cpp
|
| 2806 |
+
namespace std {
|
| 2807 |
template<class RealType = double>
|
| 2808 |
class gamma_distribution {
|
| 2809 |
public:
|
| 2810 |
// types
|
| 2811 |
using result_type = RealType;
|
|
|
|
| 2815 |
gamma_distribution() : gamma_distribution(1.0) {}
|
| 2816 |
explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
|
| 2817 |
explicit gamma_distribution(const param_type& parm);
|
| 2818 |
void reset();
|
| 2819 |
|
| 2820 |
+
// equality operators
|
| 2821 |
+
friend bool operator==(const gamma_distribution& x, const gamma_distribution& y);
|
| 2822 |
+
|
| 2823 |
// generating functions
|
| 2824 |
template<class URBG>
|
| 2825 |
result_type operator()(URBG& g);
|
| 2826 |
template<class URBG>
|
| 2827 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2831 |
RealType beta() const;
|
| 2832 |
param_type param() const;
|
| 2833 |
void param(const param_type& parm);
|
| 2834 |
result_type min() const;
|
| 2835 |
result_type max() const;
|
| 2836 |
+
|
| 2837 |
+
// inserters and extractors
|
| 2838 |
+
template<class charT, class traits>
|
| 2839 |
+
friend basic_ostream<charT, traits>&
|
| 2840 |
+
operator<<(basic_ostream<charT, traits>& os, const gamma_distribution& x);
|
| 2841 |
+
template<class charT, class traits>
|
| 2842 |
+
friend basic_istream<charT, traits>&
|
| 2843 |
+
operator>>(basic_istream<charT, traits>& is, gamma_distribution& x);
|
| 2844 |
};
|
| 2845 |
+
}
|
| 2846 |
```
|
| 2847 |
|
| 2848 |
``` cpp
|
| 2849 |
explicit gamma_distribution(RealType alpha, RealType beta = 1.0);
|
| 2850 |
```
|
|
|
|
| 2876 |
\cdot \left(\frac{x}{b}\right)^{a-1}
|
| 2877 |
\cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
|
| 2878 |
\text{ .}$$
|
| 2879 |
|
| 2880 |
``` cpp
|
| 2881 |
+
namespace std {
|
| 2882 |
template<class RealType = double>
|
| 2883 |
class weibull_distribution {
|
| 2884 |
public:
|
| 2885 |
// types
|
| 2886 |
using result_type = RealType;
|
|
|
|
| 2890 |
weibull_distribution() : weibull_distribution(1.0) {}
|
| 2891 |
explicit weibull_distribution(RealType a, RealType b = 1.0);
|
| 2892 |
explicit weibull_distribution(const param_type& parm);
|
| 2893 |
void reset();
|
| 2894 |
|
| 2895 |
+
// equality operators
|
| 2896 |
+
friend bool operator==(const weibull_distribution& x, const weibull_distribution& y);
|
| 2897 |
+
|
| 2898 |
// generating functions
|
| 2899 |
template<class URBG>
|
| 2900 |
result_type operator()(URBG& g);
|
| 2901 |
template<class URBG>
|
| 2902 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2906 |
RealType b() const;
|
| 2907 |
param_type param() const;
|
| 2908 |
void param(const param_type& parm);
|
| 2909 |
result_type min() const;
|
| 2910 |
result_type max() const;
|
| 2911 |
+
|
| 2912 |
+
// inserters and extractors
|
| 2913 |
+
template<class charT, class traits>
|
| 2914 |
+
friend basic_ostream<charT, traits>&
|
| 2915 |
+
operator<<(basic_ostream<charT, traits>& os, const weibull_distribution& x);
|
| 2916 |
+
template<class charT, class traits>
|
| 2917 |
+
friend basic_istream<charT, traits>&
|
| 2918 |
+
operator>>(basic_istream<charT, traits>& is, weibull_distribution& x);
|
| 2919 |
};
|
| 2920 |
+
}
|
| 2921 |
```
|
| 2922 |
|
| 2923 |
``` cpp
|
| 2924 |
explicit weibull_distribution(RealType a, RealType b = 1.0);
|
| 2925 |
```
|
|
|
|
| 2945 |
|
| 2946 |
##### Class template `extreme_value_distribution` <a id="rand.dist.pois.extreme">[[rand.dist.pois.extreme]]</a>
|
| 2947 |
|
| 2948 |
An `extreme_value_distribution` random number distribution produces
|
| 2949 |
random numbers x distributed according to the probability density
|
| 2950 |
+
function[^7]
|
| 2951 |
+
|
| 2952 |
+
$$p(x\,|\,a,b) = \frac{1}{b}
|
| 2953 |
\cdot \exp\left(\frac{a-x}{b} - \exp\left(\frac{a-x}{b}\right)\right)
|
| 2954 |
\text{ .}$$
|
| 2955 |
|
| 2956 |
``` cpp
|
| 2957 |
+
namespace std {
|
| 2958 |
template<class RealType = double>
|
| 2959 |
class extreme_value_distribution {
|
| 2960 |
public:
|
| 2961 |
// types
|
| 2962 |
using result_type = RealType;
|
|
|
|
| 2966 |
extreme_value_distribution() : extreme_value_distribution(0.0) {}
|
| 2967 |
explicit extreme_value_distribution(RealType a, RealType b = 1.0);
|
| 2968 |
explicit extreme_value_distribution(const param_type& parm);
|
| 2969 |
void reset();
|
| 2970 |
|
| 2971 |
+
// equality operators
|
| 2972 |
+
friend bool operator==(const extreme_value_distribution& x,
|
| 2973 |
+
const extreme_value_distribution& y);
|
| 2974 |
+
|
| 2975 |
// generating functions
|
| 2976 |
template<class URBG>
|
| 2977 |
result_type operator()(URBG& g);
|
| 2978 |
template<class URBG>
|
| 2979 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 2983 |
RealType b() const;
|
| 2984 |
param_type param() const;
|
| 2985 |
void param(const param_type& parm);
|
| 2986 |
result_type min() const;
|
| 2987 |
result_type max() const;
|
| 2988 |
+
|
| 2989 |
+
// inserters and extractors
|
| 2990 |
+
template<class charT, class traits>
|
| 2991 |
+
friend basic_ostream<charT, traits>&
|
| 2992 |
+
operator<<(basic_ostream<charT, traits>& os, const extreme_value_distribution& x);
|
| 2993 |
+
template<class charT, class traits>
|
| 2994 |
+
friend basic_istream<charT, traits>&
|
| 2995 |
+
operator>>(basic_istream<charT, traits>& is, extreme_value_distribution& x);
|
| 2996 |
};
|
| 2997 |
+
}
|
| 2998 |
```
|
| 2999 |
|
| 3000 |
``` cpp
|
| 3001 |
explicit extreme_value_distribution(RealType a, RealType b = 1.0);
|
| 3002 |
```
|
|
|
|
| 3036 |
}
|
| 3037 |
\text{ .}$$ The distribution parameters μ and σ are also known as this
|
| 3038 |
distribution’s *mean* and *standard deviation*.
|
| 3039 |
|
| 3040 |
``` cpp
|
| 3041 |
+
namespace std {
|
| 3042 |
template<class RealType = double>
|
| 3043 |
class normal_distribution {
|
| 3044 |
public:
|
| 3045 |
// types
|
| 3046 |
using result_type = RealType;
|
|
|
|
| 3050 |
normal_distribution() : normal_distribution(0.0) {}
|
| 3051 |
explicit normal_distribution(RealType mean, RealType stddev = 1.0);
|
| 3052 |
explicit normal_distribution(const param_type& parm);
|
| 3053 |
void reset();
|
| 3054 |
|
| 3055 |
+
// equality operators
|
| 3056 |
+
friend bool operator==(const normal_distribution& x, const normal_distribution& y);
|
| 3057 |
+
|
| 3058 |
// generating functions
|
| 3059 |
template<class URBG>
|
| 3060 |
result_type operator()(URBG& g);
|
| 3061 |
template<class URBG>
|
| 3062 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3066 |
RealType stddev() const;
|
| 3067 |
param_type param() const;
|
| 3068 |
void param(const param_type& parm);
|
| 3069 |
result_type min() const;
|
| 3070 |
result_type max() const;
|
| 3071 |
+
|
| 3072 |
+
// inserters and extractors
|
| 3073 |
+
template<class charT, class traits>
|
| 3074 |
+
friend basic_ostream<charT, traits>&
|
| 3075 |
+
operator<<(basic_ostream<charT, traits>& os, const normal_distribution& x);
|
| 3076 |
+
template<class charT, class traits>
|
| 3077 |
+
friend basic_istream<charT, traits>&
|
| 3078 |
+
operator>>(basic_istream<charT, traits>& is, normal_distribution& x);
|
| 3079 |
};
|
| 3080 |
+
}
|
| 3081 |
```
|
| 3082 |
|
| 3083 |
``` cpp
|
| 3084 |
explicit normal_distribution(RealType mean, RealType stddev = 1.0);
|
| 3085 |
```
|
|
|
|
| 3110 |
$$p(x\,|\,m,s) = \frac{1}{s x \sqrt{2 \pi}}
|
| 3111 |
\cdot \exp{\left(-\frac{(\ln{x} - m)^2}{2 s^2}\right)}
|
| 3112 |
\text{ .}$$
|
| 3113 |
|
| 3114 |
``` cpp
|
| 3115 |
+
namespace std {
|
| 3116 |
template<class RealType = double>
|
| 3117 |
class lognormal_distribution {
|
| 3118 |
public:
|
| 3119 |
// types
|
| 3120 |
using result_type = RealType;
|
|
|
|
| 3124 |
lognormal_distribution() : lognormal_distribution(0.0) {}
|
| 3125 |
explicit lognormal_distribution(RealType m, RealType s = 1.0);
|
| 3126 |
explicit lognormal_distribution(const param_type& parm);
|
| 3127 |
void reset();
|
| 3128 |
|
| 3129 |
+
// equality operators
|
| 3130 |
+
friend bool operator==(const lognormal_distribution& x, const lognormal_distribution& y);
|
| 3131 |
+
|
| 3132 |
// generating functions
|
| 3133 |
template<class URBG>
|
| 3134 |
result_type operator()(URBG& g);
|
| 3135 |
template<class URBG>
|
| 3136 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3140 |
RealType s() const;
|
| 3141 |
param_type param() const;
|
| 3142 |
void param(const param_type& parm);
|
| 3143 |
result_type min() const;
|
| 3144 |
result_type max() const;
|
| 3145 |
+
|
| 3146 |
+
// inserters and extractors
|
| 3147 |
+
template<class charT, class traits>
|
| 3148 |
+
friend basic_ostream<charT, traits>&
|
| 3149 |
+
operator<<(basic_ostream<charT, traits>& os, const lognormal_distribution& x);
|
| 3150 |
+
template<class charT, class traits>
|
| 3151 |
+
friend basic_istream<charT, traits>&
|
| 3152 |
+
operator>>(basic_istream<charT, traits>& is, lognormal_distribution& x);
|
| 3153 |
};
|
| 3154 |
+
}
|
| 3155 |
```
|
| 3156 |
|
| 3157 |
``` cpp
|
| 3158 |
explicit lognormal_distribution(RealType m, RealType s = 1.0);
|
| 3159 |
```
|
|
|
|
| 3182 |
A `chi_squared_distribution` random number distribution produces random
|
| 3183 |
numbers x > 0 distributed according to the probability density function
|
| 3184 |
$$p(x\,|\,n) = \frac{x^{(n/2)-1} \cdot e^{-x/2}}{\Gamma(n/2) \cdot 2^{n/2}} \text{ .}$$
|
| 3185 |
|
| 3186 |
``` cpp
|
| 3187 |
+
namespace std {
|
| 3188 |
template<class RealType = double>
|
| 3189 |
class chi_squared_distribution {
|
| 3190 |
public:
|
| 3191 |
// types
|
| 3192 |
using result_type = RealType;
|
|
|
|
| 3196 |
chi_squared_distribution() : chi_squared_distribution(1.0) {}
|
| 3197 |
explicit chi_squared_distribution(RealType n);
|
| 3198 |
explicit chi_squared_distribution(const param_type& parm);
|
| 3199 |
void reset();
|
| 3200 |
|
| 3201 |
+
// equality operators
|
| 3202 |
+
friend bool operator==(const chi_squared_distribution& x, const chi_squared_distribution& y);
|
| 3203 |
+
|
| 3204 |
// generating functions
|
| 3205 |
template<class URBG>
|
| 3206 |
result_type operator()(URBG& g);
|
| 3207 |
template<class URBG>
|
| 3208 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3211 |
RealType n() const;
|
| 3212 |
param_type param() const;
|
| 3213 |
void param(const param_type& parm);
|
| 3214 |
result_type min() const;
|
| 3215 |
result_type max() const;
|
| 3216 |
+
|
| 3217 |
+
// inserters and extractors
|
| 3218 |
+
template<class charT, class traits>
|
| 3219 |
+
friend basic_ostream<charT, traits>&
|
| 3220 |
+
operator<<(basic_ostream<charT, traits>& os, const chi_squared_distribution& x);
|
| 3221 |
+
template<class charT, class traits>
|
| 3222 |
+
friend basic_istream<charT, traits>&
|
| 3223 |
+
operator>>(basic_istream<charT, traits>& is, chi_squared_distribution& x);
|
| 3224 |
};
|
| 3225 |
+
}
|
| 3226 |
```
|
| 3227 |
|
| 3228 |
``` cpp
|
| 3229 |
explicit chi_squared_distribution(RealType n);
|
| 3230 |
```
|
|
|
|
| 3245 |
A `cauchy_distribution` random number distribution produces random
|
| 3246 |
numbers x distributed according to the probability density function
|
| 3247 |
$$p(x\,|\,a,b) = \left(\pi b \left(1 + \left(\frac{x-a}{b} \right)^2 \, \right)\right)^{-1} \text{ .}$$
|
| 3248 |
|
| 3249 |
``` cpp
|
| 3250 |
+
namespace std {
|
| 3251 |
template<class RealType = double>
|
| 3252 |
class cauchy_distribution {
|
| 3253 |
public:
|
| 3254 |
// types
|
| 3255 |
using result_type = RealType;
|
|
|
|
| 3259 |
cauchy_distribution() : cauchy_distribution(0.0) {}
|
| 3260 |
explicit cauchy_distribution(RealType a, RealType b = 1.0);
|
| 3261 |
explicit cauchy_distribution(const param_type& parm);
|
| 3262 |
void reset();
|
| 3263 |
|
| 3264 |
+
// equality operators
|
| 3265 |
+
friend bool operator==(const cauchy_distribution& x, const cauchy_distribution& y);
|
| 3266 |
+
|
| 3267 |
// generating functions
|
| 3268 |
template<class URBG>
|
| 3269 |
result_type operator()(URBG& g);
|
| 3270 |
template<class URBG>
|
| 3271 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3275 |
RealType b() const;
|
| 3276 |
param_type param() const;
|
| 3277 |
void param(const param_type& parm);
|
| 3278 |
result_type min() const;
|
| 3279 |
result_type max() const;
|
| 3280 |
+
|
| 3281 |
+
// inserters and extractors
|
| 3282 |
+
template<class charT, class traits>
|
| 3283 |
+
friend basic_ostream<charT, traits>&
|
| 3284 |
+
operator<<(basic_ostream<charT, traits>& os, const cauchy_distribution& x);
|
| 3285 |
+
template<class charT, class traits>
|
| 3286 |
+
friend basic_istream<charT, traits>&
|
| 3287 |
+
operator>>(basic_istream<charT, traits>& is, cauchy_distribution& x);
|
| 3288 |
};
|
| 3289 |
+
}
|
| 3290 |
```
|
| 3291 |
|
| 3292 |
``` cpp
|
| 3293 |
explicit cauchy_distribution(RealType a, RealType b = 1.0);
|
| 3294 |
```
|
|
|
|
| 3321 |
\cdot x^{(m/2)-1}
|
| 3322 |
\cdot \left(1 + \frac{m x}{n}\right)^{-(m + n)/2}
|
| 3323 |
\text{ .}$$
|
| 3324 |
|
| 3325 |
``` cpp
|
| 3326 |
+
namespace std {
|
| 3327 |
template<class RealType = double>
|
| 3328 |
class fisher_f_distribution {
|
| 3329 |
public:
|
| 3330 |
// types
|
| 3331 |
using result_type = RealType;
|
|
|
|
| 3335 |
fisher_f_distribution() : fisher_f_distribution(1.0) {}
|
| 3336 |
explicit fisher_f_distribution(RealType m, RealType n = 1.0);
|
| 3337 |
explicit fisher_f_distribution(const param_type& parm);
|
| 3338 |
void reset();
|
| 3339 |
|
| 3340 |
+
// equality operators
|
| 3341 |
+
friend bool operator==(const fisher_f_distribution& x, const fisher_f_distribution& y);
|
| 3342 |
+
|
| 3343 |
// generating functions
|
| 3344 |
template<class URBG>
|
| 3345 |
result_type operator()(URBG& g);
|
| 3346 |
template<class URBG>
|
| 3347 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3351 |
RealType n() const;
|
| 3352 |
param_type param() const;
|
| 3353 |
void param(const param_type& parm);
|
| 3354 |
result_type min() const;
|
| 3355 |
result_type max() const;
|
| 3356 |
+
|
| 3357 |
+
// inserters and extractors
|
| 3358 |
+
template<class charT, class traits>
|
| 3359 |
+
friend basic_ostream<charT, traits>&
|
| 3360 |
+
operator<<(basic_ostream<charT, traits>& os, const fisher_f_distribution& x);
|
| 3361 |
+
template<class charT, class traits>
|
| 3362 |
+
friend basic_istream<charT, traits>&
|
| 3363 |
+
operator>>(basic_istream<charT, traits>& is, fisher_f_distribution& x);
|
| 3364 |
};
|
| 3365 |
+
}
|
| 3366 |
```
|
| 3367 |
|
| 3368 |
``` cpp
|
| 3369 |
explicit fisher_f_distribution(RealType m, RealType n = 1);
|
| 3370 |
```
|
|
|
|
| 3396 |
\cdot \frac{\Gamma\big((n+1)/2\big)}{\Gamma(n/2)}
|
| 3397 |
\cdot \left(1 + \frac{x^2}{n} \right)^{-(n+1)/2}
|
| 3398 |
\text{ .}$$
|
| 3399 |
|
| 3400 |
``` cpp
|
| 3401 |
+
namespace std {
|
| 3402 |
template<class RealType = double>
|
| 3403 |
class student_t_distribution {
|
| 3404 |
public:
|
| 3405 |
// types
|
| 3406 |
using result_type = RealType;
|
|
|
|
| 3410 |
student_t_distribution() : student_t_distribution(1.0) {}
|
| 3411 |
explicit student_t_distribution(RealType n);
|
| 3412 |
explicit student_t_distribution(const param_type& parm);
|
| 3413 |
void reset();
|
| 3414 |
|
| 3415 |
+
// equality operators
|
| 3416 |
+
friend bool operator==(const student_t_distribution& x, const student_t_distribution& y);
|
| 3417 |
+
|
| 3418 |
// generating functions
|
| 3419 |
template<class URBG>
|
| 3420 |
result_type operator()(URBG& g);
|
| 3421 |
template<class URBG>
|
| 3422 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3425 |
RealType n() const;
|
| 3426 |
param_type param() const;
|
| 3427 |
void param(const param_type& parm);
|
| 3428 |
result_type min() const;
|
| 3429 |
result_type max() const;
|
| 3430 |
+
|
| 3431 |
+
// inserters and extractors
|
| 3432 |
+
template<class charT, class traits>
|
| 3433 |
+
friend basic_ostream<charT, traits>&
|
| 3434 |
+
operator<<(basic_ostream<charT, traits>& os, const student_t_distribution& x);
|
| 3435 |
+
template<class charT, class traits>
|
| 3436 |
+
friend basic_istream<charT, traits>&
|
| 3437 |
+
operator>>(basic_istream<charT, traits>& is, student_t_distribution& x);
|
| 3438 |
};
|
| 3439 |
+
}
|
| 3440 |
```
|
| 3441 |
|
| 3442 |
``` cpp
|
| 3443 |
explicit student_t_distribution(RealType n);
|
| 3444 |
```
|
|
|
|
| 3467 |
known as the *weights* , shall be non-negative, non-NaN, and
|
| 3468 |
non-infinity. Moreover, the following relation shall hold:
|
| 3469 |
$0 < S = w_0 + \dotsb + w_{n - 1}$.
|
| 3470 |
|
| 3471 |
``` cpp
|
| 3472 |
+
namespace std {
|
| 3473 |
template<class IntType = int>
|
| 3474 |
class discrete_distribution {
|
| 3475 |
public:
|
| 3476 |
// types
|
| 3477 |
using result_type = IntType;
|
|
|
|
| 3485 |
template<class UnaryOperation>
|
| 3486 |
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
|
| 3487 |
explicit discrete_distribution(const param_type& parm);
|
| 3488 |
void reset();
|
| 3489 |
|
| 3490 |
+
// equality operators
|
| 3491 |
+
friend bool operator==(const discrete_distribution& x, const discrete_distribution& y);
|
| 3492 |
+
|
| 3493 |
// generating functions
|
| 3494 |
template<class URBG>
|
| 3495 |
result_type operator()(URBG& g);
|
| 3496 |
template<class URBG>
|
| 3497 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3500 |
vector<double> probabilities() const;
|
| 3501 |
param_type param() const;
|
| 3502 |
void param(const param_type& parm);
|
| 3503 |
result_type min() const;
|
| 3504 |
result_type max() const;
|
| 3505 |
+
|
| 3506 |
+
// inserters and extractors
|
| 3507 |
+
template<class charT, class traits>
|
| 3508 |
+
friend basic_ostream<charT, traits>&
|
| 3509 |
+
operator<<(basic_ostream<charT, traits>& os, const discrete_distribution& x);
|
| 3510 |
+
template<class charT, class traits>
|
| 3511 |
+
friend basic_istream<charT, traits>&
|
| 3512 |
+
operator>>(basic_istream<charT, traits>& is, discrete_distribution& x);
|
| 3513 |
};
|
| 3514 |
+
}
|
| 3515 |
```
|
| 3516 |
|
| 3517 |
``` cpp
|
| 3518 |
discrete_distribution();
|
| 3519 |
```
|
|
|
|
| 3589 |
in which the values wₖ, commonly known as the *weights* , shall be
|
| 3590 |
non-negative, non-NaN, and non-infinity. Moreover, the following
|
| 3591 |
relation shall hold: 0 < S = w₀ + … + wₙ₋₁.
|
| 3592 |
|
| 3593 |
``` cpp
|
| 3594 |
+
namespace std {
|
| 3595 |
template<class RealType = double>
|
| 3596 |
class piecewise_constant_distribution {
|
| 3597 |
public:
|
| 3598 |
// types
|
| 3599 |
using result_type = RealType;
|
|
|
|
| 3610 |
piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax,
|
| 3611 |
UnaryOperation fw);
|
| 3612 |
explicit piecewise_constant_distribution(const param_type& parm);
|
| 3613 |
void reset();
|
| 3614 |
|
| 3615 |
+
// equality operators
|
| 3616 |
+
friend bool operator==(const piecewise_constant_distribution& x,
|
| 3617 |
+
const piecewise_constant_distribution& y);
|
| 3618 |
+
|
| 3619 |
// generating functions
|
| 3620 |
template<class URBG>
|
| 3621 |
result_type operator()(URBG& g);
|
| 3622 |
template<class URBG>
|
| 3623 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3627 |
vector<result_type> densities() const;
|
| 3628 |
param_type param() const;
|
| 3629 |
void param(const param_type& parm);
|
| 3630 |
result_type min() const;
|
| 3631 |
result_type max() const;
|
| 3632 |
+
|
| 3633 |
+
// inserters and extractors
|
| 3634 |
+
template<class charT, class traits>
|
| 3635 |
+
friend basic_ostream<charT, traits>&
|
| 3636 |
+
operator<<(basic_ostream<charT, traits>& os, const piecewise_constant_distribution& x);
|
| 3637 |
+
template<class charT, class traits>
|
| 3638 |
+
friend basic_istream<charT, traits>&
|
| 3639 |
+
operator>>(basic_istream<charT, traits>& is, piecewise_constant_distribution& x);
|
| 3640 |
};
|
| 3641 |
+
}
|
| 3642 |
```
|
| 3643 |
|
| 3644 |
``` cpp
|
| 3645 |
piecewise_constant_distribution();
|
| 3646 |
```
|
|
|
|
| 3739 |
shall be non-negative, non-NaN, and non-infinity. Moreover, the
|
| 3740 |
following relation shall hold:
|
| 3741 |
$$0 < S = \frac{1}{2} \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k) \text{ .}$$
|
| 3742 |
|
| 3743 |
``` cpp
|
| 3744 |
+
namespace std {
|
| 3745 |
template<class RealType = double>
|
| 3746 |
class piecewise_linear_distribution {
|
| 3747 |
public:
|
| 3748 |
// types
|
| 3749 |
using result_type = RealType;
|
|
|
|
| 3759 |
template<class UnaryOperation>
|
| 3760 |
piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
|
| 3761 |
explicit piecewise_linear_distribution(const param_type& parm);
|
| 3762 |
void reset();
|
| 3763 |
|
| 3764 |
+
// equality operators
|
| 3765 |
+
friend bool operator==(const piecewise_linear_distribution& x,
|
| 3766 |
+
const piecewise_linear_distribution& y);
|
| 3767 |
+
|
| 3768 |
// generating functions
|
| 3769 |
template<class URBG>
|
| 3770 |
result_type operator()(URBG& g);
|
| 3771 |
template<class URBG>
|
| 3772 |
result_type operator()(URBG& g, const param_type& parm);
|
|
|
|
| 3776 |
vector<result_type> densities() const;
|
| 3777 |
param_type param() const;
|
| 3778 |
void param(const param_type& parm);
|
| 3779 |
result_type min() const;
|
| 3780 |
result_type max() const;
|
| 3781 |
+
|
| 3782 |
+
// inserters and extractors
|
| 3783 |
+
template<class charT, class traits>
|
| 3784 |
+
friend basic_ostream<charT, traits>&
|
| 3785 |
+
operator<<(basic_ostream<charT, traits>& os, const piecewise_linear_distribution& x);
|
| 3786 |
+
template<class charT, class traits>
|
| 3787 |
+
friend basic_istream<charT, traits>&
|
| 3788 |
+
operator>>(basic_istream<charT, traits>& is, piecewise_linear_distribution& x);
|
| 3789 |
};
|
| 3790 |
+
}
|
| 3791 |
```
|
| 3792 |
|
| 3793 |
``` cpp
|
| 3794 |
piecewise_linear_distribution();
|
| 3795 |
```
|
|
|
|
| 3893 |
## Numeric arrays <a id="numarray">[[numarray]]</a>
|
| 3894 |
|
| 3895 |
### Header `<valarray>` synopsis <a id="valarray.syn">[[valarray.syn]]</a>
|
| 3896 |
|
| 3897 |
``` cpp
|
| 3898 |
+
#include <initializer_list> // see [initializer.list.syn]
|
| 3899 |
|
| 3900 |
namespace std {
|
| 3901 |
template<class T> class valarray; // An array of type T
|
| 3902 |
class slice; // a BLAS-like slice out of an array
|
| 3903 |
template<class T> class slice_array;
|
|
|
|
| 4056 |
|
| 4057 |
Any function returning a `valarray<T>` is permitted to return an object
|
| 4058 |
of another type, provided all the const member functions of
|
| 4059 |
`valarray<T>` are also applicable to this type. This return type shall
|
| 4060 |
not add more than two levels of template nesting over the most deeply
|
| 4061 |
+
nested argument type.[^8]
|
| 4062 |
|
| 4063 |
Implementations introducing such replacement types shall provide
|
| 4064 |
additional functions and operators as follows:
|
| 4065 |
|
| 4066 |
- for every function taking a `const valarray<T>&` other than `begin`
|
|
|
|
| 4181 |
mathematical concept of an ordered set of values. For convenience, an
|
| 4182 |
object of type `valarray<T>` is referred to as an “array” throughout the
|
| 4183 |
remainder of [[numarray]]. The illusion of higher dimensionality may be
|
| 4184 |
produced by the familiar idiom of computed indices, together with the
|
| 4185 |
powerful subsetting capabilities provided by the generalized subscript
|
| 4186 |
+
operators.[^9]
|
| 4187 |
|
| 4188 |
#### Constructors <a id="valarray.cons">[[valarray.cons]]</a>
|
| 4189 |
|
| 4190 |
``` cpp
|
| 4191 |
valarray();
|
| 4192 |
```
|
| 4193 |
|
| 4194 |
+
*Effects:* Constructs a `valarray` that has zero length.[^10]
|
| 4195 |
|
| 4196 |
``` cpp
|
| 4197 |
explicit valarray(size_t n);
|
| 4198 |
```
|
| 4199 |
|
|
|
|
| 4213 |
|
| 4214 |
*Preconditions:* \[`p`, `p + n`) is a valid range.
|
| 4215 |
|
| 4216 |
*Effects:* Constructs a `valarray` that has length `n`. The values of
|
| 4217 |
the elements of the array are initialized with the first `n` values
|
| 4218 |
+
pointed to by the first argument.[^11]
|
| 4219 |
|
| 4220 |
``` cpp
|
| 4221 |
valarray(const valarray& v);
|
| 4222 |
```
|
| 4223 |
|
| 4224 |
*Effects:* Constructs a `valarray` that has the same length as `v`. The
|
| 4225 |
elements are initialized with the values of the corresponding elements
|
| 4226 |
+
of `v`.[^12]
|
| 4227 |
|
| 4228 |
``` cpp
|
| 4229 |
valarray(valarray&& v) noexcept;
|
| 4230 |
```
|
| 4231 |
|
|
|
|
| 4336 |
|
| 4337 |
The expression `addressof(a[i]) != addressof(b[j])` evaluates to `true`
|
| 4338 |
for any two arrays `a` and `b` and for any `size_t i` and `size_t j`
|
| 4339 |
such that `i < a.size()` and `j < b.size()`.
|
| 4340 |
|
| 4341 |
+
[*Note 2*: This property indicates an absence of aliasing and can be
|
| 4342 |
+
used to advantage by optimizing compilers. Compilers can take advantage
|
| 4343 |
of inlining, constant propagation, loop fusion, tracking of pointers
|
| 4344 |
obtained from `operator new`, and other techniques to generate efficient
|
| 4345 |
`valarray`s. — *end note*]
|
| 4346 |
|
| 4347 |
The reference returned by the subscript operator for an array shall be
|
|
|
|
| 4649 |
value of `n` shifts the elements left `n` places, with zero
|
| 4650 |
fill. — *end note*]
|
| 4651 |
|
| 4652 |
[*Example 1*: If the argument has the value -2, the first two elements
|
| 4653 |
of the result will be value-initialized [[dcl.init]]; the third element
|
| 4654 |
+
of the result will be assigned the value of the first element of
|
| 4655 |
+
`*this`; etc. — *end example*]
|
| 4656 |
|
| 4657 |
``` cpp
|
| 4658 |
valarray cshift(int n) const;
|
| 4659 |
```
|
| 4660 |
|
|
|
|
| 4874 |
namespace std {
|
| 4875 |
class slice {
|
| 4876 |
public:
|
| 4877 |
slice();
|
| 4878 |
slice(size_t, size_t, size_t);
|
| 4879 |
+
slice(const slice&);
|
| 4880 |
|
| 4881 |
size_t start() const;
|
| 4882 |
size_t size() const;
|
| 4883 |
size_t stride() const;
|
| 4884 |
|
|
|
|
| 4886 |
};
|
| 4887 |
}
|
| 4888 |
```
|
| 4889 |
|
| 4890 |
The `slice` class represents a BLAS-like slice from an array. Such a
|
| 4891 |
+
slice is specified by a starting index, a length, and a stride.[^13]
|
| 4892 |
|
| 4893 |
#### Constructors <a id="cons.slice">[[cons.slice]]</a>
|
| 4894 |
|
| 4895 |
``` cpp
|
| 4896 |
slice();
|
| 4897 |
slice(size_t start, size_t length, size_t stride);
|
|
|
|
| 4898 |
```
|
| 4899 |
|
| 4900 |
The default constructor is equivalent to `slice(0, 0, 0)`. A default
|
| 4901 |
constructor is provided only to permit the declaration of arrays of
|
| 4902 |
slices. The constructor with arguments for a slice takes a start,
|
|
|
|
| 5081 |
|
| 5082 |
``` cpp
|
| 5083 |
gslice();
|
| 5084 |
gslice(size_t start, const valarray<size_t>& lengths,
|
| 5085 |
const valarray<size_t>& strides);
|
|
|
|
| 5086 |
```
|
| 5087 |
|
| 5088 |
The default constructor is equivalent to
|
| 5089 |
`gslice(0, valarray<size_t>(), valarray<size_t>())`. The constructor
|
| 5090 |
with arguments builds a `gslice` based on a specification of start,
|
|
|
|
| 5222 |
```
|
| 5223 |
|
| 5224 |
This template is a helper template used by the mask subscript operator:
|
| 5225 |
|
| 5226 |
``` cpp
|
| 5227 |
+
mask_array<T> valarray<T>::operator[](const valarray<bool>&);
|
| 5228 |
```
|
| 5229 |
|
| 5230 |
It has reference semantics to a subset of an array specified by a
|
| 5231 |
boolean mask. Thus, the expression `a[mask] = b;` has the effect of
|
| 5232 |
assigning the elements of `b` to the masked elements in `a` (those for
|
|
|
|
| 5239 |
const mask_array& operator=(const mask_array&) const;
|
| 5240 |
```
|
| 5241 |
|
| 5242 |
These assignment operators have reference semantics, assigning the
|
| 5243 |
values of the argument array elements to selected elements of the
|
| 5244 |
+
`valarray<T>` object to which the `mask_array` object refers.
|
| 5245 |
|
| 5246 |
#### Compound assignment <a id="mask.array.comp.assign">[[mask.array.comp.assign]]</a>
|
| 5247 |
|
| 5248 |
``` cpp
|
| 5249 |
void operator*= (const valarray<T>&) const;
|
|
|
|
| 5258 |
void operator>>=(const valarray<T>&) const;
|
| 5259 |
```
|
| 5260 |
|
| 5261 |
These compound assignments have reference semantics, applying the
|
| 5262 |
indicated operation to the elements of the argument array and selected
|
| 5263 |
+
elements of the `valarray<T>` object to which the `mask_array` object
|
| 5264 |
+
refers.
|
| 5265 |
|
| 5266 |
#### Fill function <a id="mask.array.fill">[[mask.array.fill]]</a>
|
| 5267 |
|
| 5268 |
``` cpp
|
| 5269 |
void operator=(const T&) const;
|
|
|
|
| 5307 |
|
| 5308 |
This template is a helper template used by the indirect subscript
|
| 5309 |
operator
|
| 5310 |
|
| 5311 |
``` cpp
|
| 5312 |
+
indirect_array<T> valarray<T>::operator[](const valarray<size_t>&);
|
| 5313 |
```
|
| 5314 |
|
| 5315 |
It has reference semantics to a subset of an array specified by an
|
| 5316 |
`indirect_array`. Thus, the expression `a[{}indirect] = b;` has the
|
| 5317 |
effect of assigning the elements of `b` to the elements in `a` whose
|
|
|
|
| 5438 |
#define MATH_ERREXCEPT see below
|
| 5439 |
|
| 5440 |
#define math_errhandling see below
|
| 5441 |
|
| 5442 |
namespace std {
|
| 5443 |
+
floating-point-type acos(floating-point-type x);
|
|
|
|
|
|
|
| 5444 |
float acosf(float x);
|
| 5445 |
long double acosl(long double x);
|
| 5446 |
|
| 5447 |
+
floating-point-type asin(floating-point-type x);
|
|
|
|
|
|
|
| 5448 |
float asinf(float x);
|
| 5449 |
long double asinl(long double x);
|
| 5450 |
|
| 5451 |
+
floating-point-type atan(floating-point-type x);
|
|
|
|
|
|
|
| 5452 |
float atanf(float x);
|
| 5453 |
long double atanl(long double x);
|
| 5454 |
|
| 5455 |
+
floating-point-type atan2(floating-point-type y, floating-point-type x);
|
|
|
|
|
|
|
| 5456 |
float atan2f(float y, float x);
|
| 5457 |
long double atan2l(long double y, long double x);
|
| 5458 |
|
| 5459 |
+
floating-point-type cos(floating-point-type x);
|
|
|
|
|
|
|
| 5460 |
float cosf(float x);
|
| 5461 |
long double cosl(long double x);
|
| 5462 |
|
| 5463 |
+
floating-point-type sin(floating-point-type x);
|
|
|
|
|
|
|
| 5464 |
float sinf(float x);
|
| 5465 |
long double sinl(long double x);
|
| 5466 |
|
| 5467 |
+
floating-point-type tan(floating-point-type x);
|
|
|
|
|
|
|
| 5468 |
float tanf(float x);
|
| 5469 |
long double tanl(long double x);
|
| 5470 |
|
| 5471 |
+
floating-point-type acosh(floating-point-type x);
|
|
|
|
|
|
|
| 5472 |
float acoshf(float x);
|
| 5473 |
long double acoshl(long double x);
|
| 5474 |
|
| 5475 |
+
floating-point-type asinh(floating-point-type x);
|
|
|
|
|
|
|
| 5476 |
float asinhf(float x);
|
| 5477 |
long double asinhl(long double x);
|
| 5478 |
|
| 5479 |
+
floating-point-type atanh(floating-point-type x);
|
|
|
|
|
|
|
| 5480 |
float atanhf(float x);
|
| 5481 |
long double atanhl(long double x);
|
| 5482 |
|
| 5483 |
+
floating-point-type cosh(floating-point-type x);
|
|
|
|
|
|
|
| 5484 |
float coshf(float x);
|
| 5485 |
long double coshl(long double x);
|
| 5486 |
|
| 5487 |
+
floating-point-type sinh(floating-point-type x);
|
|
|
|
|
|
|
| 5488 |
float sinhf(float x);
|
| 5489 |
long double sinhl(long double x);
|
| 5490 |
|
| 5491 |
+
floating-point-type tanh(floating-point-type x);
|
|
|
|
|
|
|
| 5492 |
float tanhf(float x);
|
| 5493 |
long double tanhl(long double x);
|
| 5494 |
|
| 5495 |
+
floating-point-type exp(floating-point-type x);
|
|
|
|
|
|
|
| 5496 |
float expf(float x);
|
| 5497 |
long double expl(long double x);
|
| 5498 |
|
| 5499 |
+
floating-point-type exp2(floating-point-type x);
|
|
|
|
|
|
|
| 5500 |
float exp2f(float x);
|
| 5501 |
long double exp2l(long double x);
|
| 5502 |
|
| 5503 |
+
floating-point-type expm1(floating-point-type x);
|
|
|
|
|
|
|
| 5504 |
float expm1f(float x);
|
| 5505 |
long double expm1l(long double x);
|
| 5506 |
|
| 5507 |
+
constexpr floating-point-type frexp(floating-point-type value, int* exp);
|
| 5508 |
+
constexpr float frexpf(float value, int* exp);
|
| 5509 |
+
constexpr long double frexpl(long double value, int* exp);
|
|
|
|
|
|
|
| 5510 |
|
| 5511 |
+
constexpr int ilogb(floating-point-type x);
|
| 5512 |
+
constexpr int ilogbf(float x);
|
| 5513 |
+
constexpr int ilogbl(long double x);
|
|
|
|
|
|
|
| 5514 |
|
| 5515 |
+
constexpr floating-point-type ldexp(floating-point-type x, int exp);
|
| 5516 |
+
constexpr float ldexpf(float x, int exp);
|
| 5517 |
+
constexpr long double ldexpl(long double x, int exp);
|
|
|
|
|
|
|
| 5518 |
|
| 5519 |
+
floating-point-type log(floating-point-type x);
|
|
|
|
|
|
|
| 5520 |
float logf(float x);
|
| 5521 |
long double logl(long double x);
|
| 5522 |
|
| 5523 |
+
floating-point-type log10(floating-point-type x);
|
|
|
|
|
|
|
| 5524 |
float log10f(float x);
|
| 5525 |
long double log10l(long double x);
|
| 5526 |
|
| 5527 |
+
floating-point-type log1p(floating-point-type x);
|
|
|
|
|
|
|
| 5528 |
float log1pf(float x);
|
| 5529 |
long double log1pl(long double x);
|
| 5530 |
|
| 5531 |
+
floating-point-type log2(floating-point-type x);
|
|
|
|
|
|
|
| 5532 |
float log2f(float x);
|
| 5533 |
long double log2l(long double x);
|
| 5534 |
|
| 5535 |
+
constexpr floating-point-type logb(floating-point-type x);
|
| 5536 |
+
constexpr float logbf(float x);
|
| 5537 |
+
constexpr long double logbl(long double x);
|
|
|
|
|
|
|
| 5538 |
|
| 5539 |
+
constexpr floating-point-type modf(floating-point-type value, floating-point-type* iptr);
|
| 5540 |
+
constexpr float modff(float value, float* iptr);
|
| 5541 |
+
constexpr long double modfl(long double value, long double* iptr);
|
|
|
|
|
|
|
| 5542 |
|
| 5543 |
+
constexpr floating-point-type scalbn(floating-point-type x, int n);
|
| 5544 |
+
constexpr float scalbnf(float x, int n);
|
| 5545 |
+
constexpr long double scalbnl(long double x, int n);
|
|
|
|
|
|
|
| 5546 |
|
| 5547 |
+
constexpr floating-point-type scalbln(floating-point-type x, long int n);
|
| 5548 |
+
constexpr float scalblnf(float x, long int n);
|
| 5549 |
+
constexpr long double scalblnl(long double x, long int n);
|
|
|
|
|
|
|
| 5550 |
|
| 5551 |
+
floating-point-type cbrt(floating-point-type x);
|
|
|
|
|
|
|
| 5552 |
float cbrtf(float x);
|
| 5553 |
long double cbrtl(long double x);
|
| 5554 |
|
| 5555 |
// [c.math.abs], absolute values
|
| 5556 |
+
constexpr int abs(int j);
|
| 5557 |
+
constexpr long int abs(long int j);
|
| 5558 |
+
constexpr long long int abs(long long int j);
|
| 5559 |
+
constexpr floating-point-type abs(floating-point-type j);
|
|
|
|
|
|
|
| 5560 |
|
| 5561 |
+
constexpr floating-point-type fabs(floating-point-type x);
|
| 5562 |
+
constexpr float fabsf(float x);
|
| 5563 |
+
constexpr long double fabsl(long double x);
|
|
|
|
|
|
|
| 5564 |
|
| 5565 |
+
floating-point-type hypot(floating-point-type x, floating-point-type y);
|
|
|
|
|
|
|
| 5566 |
float hypotf(float x, float y);
|
| 5567 |
long double hypotl(long double x, long double y);
|
| 5568 |
|
| 5569 |
// [c.math.hypot3], three-dimensional hypotenuse
|
| 5570 |
+
floating-point-type hypot(floating-point-type x, floating-point-type y,
|
| 5571 |
+
floating-point-type z);
|
|
|
|
| 5572 |
|
| 5573 |
+
floating-point-type pow(floating-point-type x, floating-point-type y);
|
|
|
|
|
|
|
| 5574 |
float powf(float x, float y);
|
| 5575 |
long double powl(long double x, long double y);
|
| 5576 |
|
| 5577 |
+
floating-point-type sqrt(floating-point-type x);
|
|
|
|
|
|
|
| 5578 |
float sqrtf(float x);
|
| 5579 |
long double sqrtl(long double x);
|
| 5580 |
|
| 5581 |
+
floating-point-type erf(floating-point-type x);
|
|
|
|
|
|
|
| 5582 |
float erff(float x);
|
| 5583 |
long double erfl(long double x);
|
| 5584 |
|
| 5585 |
+
floating-point-type erfc(floating-point-type x);
|
|
|
|
|
|
|
| 5586 |
float erfcf(float x);
|
| 5587 |
long double erfcl(long double x);
|
| 5588 |
|
| 5589 |
+
floating-point-type lgamma(floating-point-type x);
|
|
|
|
|
|
|
| 5590 |
float lgammaf(float x);
|
| 5591 |
long double lgammal(long double x);
|
| 5592 |
|
| 5593 |
+
floating-point-type tgamma(floating-point-type x);
|
|
|
|
|
|
|
| 5594 |
float tgammaf(float x);
|
| 5595 |
long double tgammal(long double x);
|
| 5596 |
|
| 5597 |
+
constexpr floating-point-type ceil(floating-point-type x);
|
| 5598 |
+
constexpr float ceilf(float x);
|
| 5599 |
+
constexpr long double ceill(long double x);
|
|
|
|
|
|
|
| 5600 |
|
| 5601 |
+
constexpr floating-point-type floor(floating-point-type x);
|
| 5602 |
+
constexpr float floorf(float x);
|
| 5603 |
+
constexpr long double floorl(long double x);
|
|
|
|
|
|
|
| 5604 |
|
| 5605 |
+
floating-point-type nearbyint(floating-point-type x);
|
|
|
|
|
|
|
| 5606 |
float nearbyintf(float x);
|
| 5607 |
long double nearbyintl(long double x);
|
| 5608 |
|
| 5609 |
+
floating-point-type rint(floating-point-type x);
|
|
|
|
|
|
|
| 5610 |
float rintf(float x);
|
| 5611 |
long double rintl(long double x);
|
| 5612 |
|
| 5613 |
+
long int lrint(floating-point-type x);
|
|
|
|
|
|
|
| 5614 |
long int lrintf(float x);
|
| 5615 |
long int lrintl(long double x);
|
| 5616 |
|
| 5617 |
+
long long int llrint(floating-point-type x);
|
|
|
|
|
|
|
| 5618 |
long long int llrintf(float x);
|
| 5619 |
long long int llrintl(long double x);
|
| 5620 |
|
| 5621 |
+
constexpr floating-point-type round(floating-point-type x);
|
| 5622 |
+
constexpr float roundf(float x);
|
| 5623 |
+
constexpr long double roundl(long double x);
|
|
|
|
|
|
|
| 5624 |
|
| 5625 |
+
constexpr long int lround(floating-point-type x);
|
| 5626 |
+
constexpr long int lroundf(float x);
|
| 5627 |
+
constexpr long int lroundl(long double x);
|
|
|
|
|
|
|
| 5628 |
|
| 5629 |
+
constexpr long long int llround(floating-point-type x);
|
| 5630 |
+
constexpr long long int llroundf(float x);
|
| 5631 |
+
constexpr long long int llroundl(long double x);
|
|
|
|
|
|
|
| 5632 |
|
| 5633 |
+
constexpr floating-point-type trunc(floating-point-type x);
|
| 5634 |
+
constexpr float truncf(float x);
|
| 5635 |
+
constexpr long double truncl(long double x);
|
|
|
|
|
|
|
| 5636 |
|
| 5637 |
+
constexpr floating-point-type fmod(floating-point-type x, floating-point-type y);
|
| 5638 |
+
constexpr float fmodf(float x, float y);
|
| 5639 |
+
constexpr long double fmodl(long double x, long double y);
|
|
|
|
|
|
|
| 5640 |
|
| 5641 |
+
constexpr floating-point-type remainder(floating-point-type x, floating-point-type y);
|
| 5642 |
+
constexpr float remainderf(float x, float y);
|
| 5643 |
+
constexpr long double remainderl(long double x, long double y);
|
|
|
|
|
|
|
| 5644 |
|
| 5645 |
+
constexpr floating-point-type remquo(floating-point-type x, floating-point-type y, int* quo);
|
| 5646 |
+
constexpr float remquof(float x, float y, int* quo);
|
| 5647 |
+
constexpr long double remquol(long double x, long double y, int* quo);
|
|
|
|
|
|
|
| 5648 |
|
| 5649 |
+
constexpr floating-point-type copysign(floating-point-type x, floating-point-type y);
|
| 5650 |
+
constexpr float copysignf(float x, float y);
|
| 5651 |
+
constexpr long double copysignl(long double x, long double y);
|
|
|
|
|
|
|
| 5652 |
|
| 5653 |
double nan(const char* tagp);
|
| 5654 |
float nanf(const char* tagp);
|
| 5655 |
long double nanl(const char* tagp);
|
| 5656 |
|
| 5657 |
+
constexpr floating-point-type nextafter(floating-point-type x, floating-point-type y);
|
| 5658 |
+
constexpr float nextafterf(float x, float y);
|
| 5659 |
+
constexpr long double nextafterl(long double x, long double y);
|
|
|
|
|
|
|
| 5660 |
|
| 5661 |
+
constexpr floating-point-type nexttoward(floating-point-type x, long double y);
|
| 5662 |
+
constexpr float nexttowardf(float x, long double y);
|
| 5663 |
+
constexpr long double nexttowardl(long double x, long double y);
|
|
|
|
|
|
|
| 5664 |
|
| 5665 |
+
constexpr floating-point-type fdim(floating-point-type x, floating-point-type y);
|
| 5666 |
+
constexpr float fdimf(float x, float y);
|
| 5667 |
+
constexpr long double fdiml(long double x, long double y);
|
|
|
|
|
|
|
| 5668 |
|
| 5669 |
+
constexpr floating-point-type fmax(floating-point-type x, floating-point-type y);
|
| 5670 |
+
constexpr float fmaxf(float x, float y);
|
| 5671 |
+
constexpr long double fmaxl(long double x, long double y);
|
|
|
|
|
|
|
| 5672 |
|
| 5673 |
+
constexpr floating-point-type fmin(floating-point-type x, floating-point-type y);
|
| 5674 |
+
constexpr float fminf(float x, float y);
|
| 5675 |
+
constexpr long double fminl(long double x, long double y);
|
|
|
|
|
|
|
| 5676 |
|
| 5677 |
+
constexpr floating-point-type fma(floating-point-type x, floating-point-type y,
|
| 5678 |
+
floating-point-type z);
|
| 5679 |
+
constexpr float fmaf(float x, float y, float z);
|
| 5680 |
+
constexpr long double fmal(long double x, long double y, long double z);
|
|
|
|
| 5681 |
|
| 5682 |
// [c.math.lerp], linear interpolation
|
| 5683 |
+
constexpr floating-point-type lerp(floating-point-type a, floating-point-type b,
|
| 5684 |
+
floating-point-type t) noexcept;
|
|
|
|
| 5685 |
|
| 5686 |
// [c.math.fpclass], classification / comparison functions
|
| 5687 |
+
constexpr int fpclassify(floating-point-type x);
|
| 5688 |
+
constexpr bool isfinite(floating-point-type x);
|
| 5689 |
+
constexpr bool isinf(floating-point-type x);
|
| 5690 |
+
constexpr bool isnan(floating-point-type x);
|
| 5691 |
+
constexpr bool isnormal(floating-point-type x);
|
| 5692 |
+
constexpr bool signbit(floating-point-type x);
|
| 5693 |
+
constexpr bool isgreater(floating-point-type x, floating-point-type y);
|
| 5694 |
+
constexpr bool isgreaterequal(floating-point-type x, floating-point-type y);
|
| 5695 |
+
constexpr bool isless(floating-point-type x, floating-point-type y);
|
| 5696 |
+
constexpr bool islessequal(floating-point-type x, floating-point-type y);
|
| 5697 |
+
constexpr bool islessgreater(floating-point-type x, floating-point-type y);
|
| 5698 |
+
constexpr bool isunordered(floating-point-type x, floating-point-type y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5699 |
|
| 5700 |
// [sf.cmath], mathematical special functions
|
| 5701 |
|
| 5702 |
// [sf.cmath.assoc.laguerre], associated Laguerre polynomials
|
| 5703 |
+
floating-point-type assoc_laguerre(unsigned n, unsigned m, floating-point-type x);
|
| 5704 |
float assoc_laguerref(unsigned n, unsigned m, float x);
|
| 5705 |
long double assoc_laguerrel(unsigned n, unsigned m, long double x);
|
| 5706 |
|
| 5707 |
// [sf.cmath.assoc.legendre], associated Legendre functions
|
| 5708 |
+
floating-point-type assoc_legendre(unsigned l, unsigned m, floating-point-type x);
|
| 5709 |
float assoc_legendref(unsigned l, unsigned m, float x);
|
| 5710 |
long double assoc_legendrel(unsigned l, unsigned m, long double x);
|
| 5711 |
|
| 5712 |
// [sf.cmath.beta], beta function
|
| 5713 |
+
floating-point-type beta(floating-point-type x, floating-point-type y);
|
| 5714 |
float betaf(float x, float y);
|
| 5715 |
long double betal(long double x, long double y);
|
| 5716 |
|
| 5717 |
// [sf.cmath.comp.ellint.1], complete elliptic integral of the first kind
|
| 5718 |
+
floating-point-type comp_ellint_1(floating-point-type k);
|
| 5719 |
float comp_ellint_1f(float k);
|
| 5720 |
long double comp_ellint_1l(long double k);
|
| 5721 |
|
| 5722 |
// [sf.cmath.comp.ellint.2], complete elliptic integral of the second kind
|
| 5723 |
+
floating-point-type comp_ellint_2(floating-point-type k);
|
| 5724 |
float comp_ellint_2f(float k);
|
| 5725 |
long double comp_ellint_2l(long double k);
|
| 5726 |
|
| 5727 |
// [sf.cmath.comp.ellint.3], complete elliptic integral of the third kind
|
| 5728 |
+
floating-point-type comp_ellint_3(floating-point-type k, floating-point-type nu);
|
| 5729 |
float comp_ellint_3f(float k, float nu);
|
| 5730 |
long double comp_ellint_3l(long double k, long double nu);
|
| 5731 |
|
| 5732 |
// [sf.cmath.cyl.bessel.i], regular modified cylindrical Bessel functions
|
| 5733 |
+
floating-point-type cyl_bessel_i(floating-point-type nu, floating-point-type x);
|
| 5734 |
float cyl_bessel_if(float nu, float x);
|
| 5735 |
long double cyl_bessel_il(long double nu, long double x);
|
| 5736 |
|
| 5737 |
// [sf.cmath.cyl.bessel.j], cylindrical Bessel functions of the first kind
|
| 5738 |
+
floating-point-type cyl_bessel_j(floating-point-type nu, floating-point-type x);
|
| 5739 |
float cyl_bessel_jf(float nu, float x);
|
| 5740 |
long double cyl_bessel_jl(long double nu, long double x);
|
| 5741 |
|
| 5742 |
// [sf.cmath.cyl.bessel.k], irregular modified cylindrical Bessel functions
|
| 5743 |
+
floating-point-type cyl_bessel_k(floating-point-type nu, floating-point-type x);
|
| 5744 |
float cyl_bessel_kf(float nu, float x);
|
| 5745 |
long double cyl_bessel_kl(long double nu, long double x);
|
| 5746 |
|
| 5747 |
+
// [sf.cmath.cyl.neumann], cylindrical Neumann functions
|
| 5748 |
// cylindrical Bessel functions of the second kind
|
| 5749 |
+
floating-point-type cyl_neumann(floating-point-type nu, floating-point-type x);
|
| 5750 |
float cyl_neumannf(float nu, float x);
|
| 5751 |
long double cyl_neumannl(long double nu, long double x);
|
| 5752 |
|
| 5753 |
// [sf.cmath.ellint.1], incomplete elliptic integral of the first kind
|
| 5754 |
+
floating-point-type ellint_1(floating-point-type k, floating-point-type phi);
|
| 5755 |
float ellint_1f(float k, float phi);
|
| 5756 |
long double ellint_1l(long double k, long double phi);
|
| 5757 |
|
| 5758 |
// [sf.cmath.ellint.2], incomplete elliptic integral of the second kind
|
| 5759 |
+
floating-point-type ellint_2(floating-point-type k, floating-point-type phi);
|
| 5760 |
float ellint_2f(float k, float phi);
|
| 5761 |
long double ellint_2l(long double k, long double phi);
|
| 5762 |
|
| 5763 |
// [sf.cmath.ellint.3], incomplete elliptic integral of the third kind
|
| 5764 |
+
floating-point-type ellint_3(floating-point-type k, floating-point-type nu,
|
| 5765 |
+
floating-point-type phi);
|
| 5766 |
float ellint_3f(float k, float nu, float phi);
|
| 5767 |
long double ellint_3l(long double k, long double nu, long double phi);
|
| 5768 |
|
| 5769 |
// [sf.cmath.expint], exponential integral
|
| 5770 |
+
floating-point-type expint(floating-point-type x);
|
| 5771 |
float expintf(float x);
|
| 5772 |
long double expintl(long double x);
|
| 5773 |
|
| 5774 |
// [sf.cmath.hermite], Hermite polynomials
|
| 5775 |
+
floating-point-type hermite(unsigned n, floating-point-type x);
|
| 5776 |
float hermitef(unsigned n, float x);
|
| 5777 |
long double hermitel(unsigned n, long double x);
|
| 5778 |
|
| 5779 |
// [sf.cmath.laguerre], Laguerre polynomials
|
| 5780 |
+
floating-point-type laguerre(unsigned n, floating-point-type x);
|
| 5781 |
float laguerref(unsigned n, float x);
|
| 5782 |
long double laguerrel(unsigned n, long double x);
|
| 5783 |
|
| 5784 |
// [sf.cmath.legendre], Legendre polynomials
|
| 5785 |
+
floating-point-type legendre(unsigned l, floating-point-type x);
|
| 5786 |
float legendref(unsigned l, float x);
|
| 5787 |
long double legendrel(unsigned l, long double x);
|
| 5788 |
|
| 5789 |
// [sf.cmath.riemann.zeta], Riemann zeta function
|
| 5790 |
+
floating-point-type riemann_zeta(floating-point-type x);
|
| 5791 |
float riemann_zetaf(float x);
|
| 5792 |
long double riemann_zetal(long double x);
|
| 5793 |
|
| 5794 |
// [sf.cmath.sph.bessel], spherical Bessel functions of the first kind
|
| 5795 |
+
floating-point-type sph_bessel(unsigned n, floating-point-type x);
|
| 5796 |
float sph_besself(unsigned n, float x);
|
| 5797 |
long double sph_bessell(unsigned n, long double x);
|
| 5798 |
|
| 5799 |
// [sf.cmath.sph.legendre], spherical associated Legendre functions
|
| 5800 |
+
floating-point-type sph_legendre(unsigned l, unsigned m, floating-point-type theta);
|
| 5801 |
float sph_legendref(unsigned l, unsigned m, float theta);
|
| 5802 |
long double sph_legendrel(unsigned l, unsigned m, long double theta);
|
| 5803 |
|
| 5804 |
// [sf.cmath.sph.neumann], spherical Neumann functions;
|
| 5805 |
// spherical Bessel functions of the second kind
|
| 5806 |
+
floating-point-type sph_neumann(unsigned n, floating-point-type x);
|
| 5807 |
float sph_neumannf(unsigned n, float x);
|
| 5808 |
long double sph_neumannl(unsigned n, long double x);
|
| 5809 |
}
|
| 5810 |
```
|
| 5811 |
|
| 5812 |
The contents and meaning of the header `<cmath>` are the same as the C
|
| 5813 |
standard library header `<math.h>`, with the addition of a
|
| 5814 |
+
three-dimensional hypotenuse function [[c.math.hypot3]], a linear
|
| 5815 |
+
interpolation function [[c.math.lerp]], and the mathematical special
|
| 5816 |
+
functions described in [[sf.cmath]].
|
| 5817 |
|
| 5818 |
[*Note 1*: Several functions have additional overloads in this
|
| 5819 |
document, but they have the same behavior as in the C standard library
|
| 5820 |
[[library.c]]. — *end note*]
|
| 5821 |
|
| 5822 |
+
For each function with at least one parameter of type
|
| 5823 |
+
*floating-point-type*, the implementation provides an overload for each
|
| 5824 |
+
cv-unqualified floating-point type [[basic.fundamental]] where all uses
|
| 5825 |
+
of *floating-point-type* in the function signature are replaced with
|
| 5826 |
+
that floating-point type.
|
| 5827 |
|
| 5828 |
+
For each function with at least one parameter of type
|
| 5829 |
+
*floating-point-type* other than `abs`, the implementation also provides
|
| 5830 |
+
additional overloads sufficient to ensure that, if every argument
|
| 5831 |
+
corresponding to a *floating-point-type* parameter has arithmetic type,
|
| 5832 |
+
then every such argument is effectively cast to the floating-point type
|
| 5833 |
+
with the greatest floating-point conversion rank and greatest
|
| 5834 |
+
floating-point conversion subrank among the types of all such arguments,
|
| 5835 |
+
where arguments of integer type are considered to have the same
|
| 5836 |
+
floating-point conversion rank as `double`. If no such floating-point
|
| 5837 |
+
type with the greatest rank and subrank exists, then overload resolution
|
| 5838 |
+
does not result in a usable candidate [[over.match.general]] from the
|
| 5839 |
+
overloads provided by the implementation.
|
| 5840 |
|
| 5841 |
+
An invocation of `nexttoward` is ill-formed if the argument
|
| 5842 |
+
corresponding to the *floating-point-type* parameter has extended
|
| 5843 |
+
floating-point type.
|
| 5844 |
|
| 5845 |
+
See also: ISO C 7.12
|
| 5846 |
|
| 5847 |
### Absolute values <a id="c.math.abs">[[c.math.abs]]</a>
|
| 5848 |
|
| 5849 |
[*Note 1*: The headers `<cstdlib>` and `<cmath>` declare the functions
|
| 5850 |
described in this subclause. — *end note*]
|
| 5851 |
|
| 5852 |
``` cpp
|
| 5853 |
+
constexpr int abs(int j);
|
| 5854 |
+
constexpr long int abs(long int j);
|
| 5855 |
+
constexpr long long int abs(long long int j);
|
|
|
|
|
|
|
|
|
|
| 5856 |
```
|
| 5857 |
|
| 5858 |
+
*Effects:* These functions have the semantics specified in the C
|
| 5859 |
+
standard library for the functions `abs`, `labs`, and `llabs`,
|
| 5860 |
+
respectively.
|
| 5861 |
|
| 5862 |
+
*Remarks:* If `abs` is called with an argument of type `X` for which
|
| 5863 |
`is_unsigned_v<X>` is `true` and if `X` cannot be converted to `int` by
|
| 5864 |
integral promotion [[conv.prom]], the program is ill-formed.
|
| 5865 |
|
| 5866 |
[*Note 1*: Arguments that can be promoted to `int` are permitted for
|
| 5867 |
compatibility with C. — *end note*]
|
| 5868 |
|
| 5869 |
+
``` cpp
|
| 5870 |
+
constexpr floating-point-type abs(floating-point-type x);
|
| 5871 |
+
```
|
| 5872 |
+
|
| 5873 |
+
*Returns:* The absolute value of `x`.
|
| 5874 |
+
|
| 5875 |
See also: ISO C 7.12.7.2, 7.22.6.1
|
| 5876 |
|
| 5877 |
### Three-dimensional hypotenuse <a id="c.math.hypot3">[[c.math.hypot3]]</a>
|
| 5878 |
|
| 5879 |
``` cpp
|
| 5880 |
+
floating-point-type hypot(floating-point-type x, floating-point-type y, floating-point-type z);
|
|
|
|
|
|
|
| 5881 |
```
|
| 5882 |
|
| 5883 |
*Returns:* $\sqrt{x^2+y^2+z^2}$.
|
| 5884 |
|
| 5885 |
### Linear interpolation <a id="c.math.lerp">[[c.math.lerp]]</a>
|
| 5886 |
|
| 5887 |
``` cpp
|
| 5888 |
+
constexpr floating-point-type lerp(floating-point-type a, floating-point-type b,
|
| 5889 |
+
floating-point-type t) noexcept;
|
|
|
|
| 5890 |
```
|
| 5891 |
|
| 5892 |
*Returns:* a+t(b-a).
|
| 5893 |
|
| 5894 |
*Remarks:* Let `r` be the value returned. If
|
|
|
|
| 5907 |
|
| 5908 |
### Classification / comparison functions <a id="c.math.fpclass">[[c.math.fpclass]]</a>
|
| 5909 |
|
| 5910 |
The classification / comparison functions behave the same as the C
|
| 5911 |
macros with the corresponding names defined in the C standard library.
|
|
|
|
| 5912 |
|
| 5913 |
+
See also: ISO C 7.12.3, 7.12.4
|
| 5914 |
|
| 5915 |
### Mathematical special functions <a id="sf.cmath">[[sf.cmath]]</a>
|
| 5916 |
|
| 5917 |
+
#### General <a id="sf.cmath.general">[[sf.cmath.general]]</a>
|
|
|
|
|
|
|
|
|
|
| 5918 |
|
| 5919 |
+
If any argument value to any of the functions specified in [[sf.cmath]]
|
| 5920 |
+
is a NaN (Not a Number), the function shall return a NaN but it shall
|
| 5921 |
+
not report a domain error. Otherwise, the function shall report a domain
|
| 5922 |
+
error for just those argument values for which:
|
| 5923 |
+
|
| 5924 |
+
- the function description’s *Returns:* element explicitly specifies a
|
| 5925 |
domain and those argument values fall outside the specified domain, or
|
| 5926 |
- the corresponding mathematical function value has a nonzero imaginary
|
| 5927 |
component, or
|
| 5928 |
- the corresponding mathematical function is not mathematically
|
| 5929 |
+
defined.[^14]
|
| 5930 |
|
| 5931 |
Unless otherwise specified, each function is defined for all finite
|
| 5932 |
values, for negative infinity, and for positive infinity.
|
| 5933 |
|
| 5934 |
#### Associated Laguerre polynomials <a id="sf.cmath.assoc.laguerre">[[sf.cmath.assoc.laguerre]]</a>
|
| 5935 |
|
| 5936 |
``` cpp
|
| 5937 |
+
floating-point-type assoc_laguerre(unsigned n, unsigned m, floating-point-type x);
|
| 5938 |
float assoc_laguerref(unsigned n, unsigned m, float x);
|
| 5939 |
long double assoc_laguerrel(unsigned n, unsigned m, long double x);
|
| 5940 |
```
|
| 5941 |
|
| 5942 |
*Effects:* These functions compute the associated Laguerre polynomials
|
|
|
|
| 5951 |
*implementation-defined* if `n >= 128` or if `m >= 128`.
|
| 5952 |
|
| 5953 |
#### Associated Legendre functions <a id="sf.cmath.assoc.legendre">[[sf.cmath.assoc.legendre]]</a>
|
| 5954 |
|
| 5955 |
``` cpp
|
| 5956 |
+
floating-point-type assoc_legendre(unsigned l, unsigned m, floating-point-type x);
|
| 5957 |
float assoc_legendref(unsigned l, unsigned m, float x);
|
| 5958 |
long double assoc_legendrel(unsigned l, unsigned m, long double x);
|
| 5959 |
```
|
| 5960 |
|
| 5961 |
*Effects:* These functions compute the associated Legendre functions of
|
|
|
|
| 5970 |
*implementation-defined* if `l >= 128`.
|
| 5971 |
|
| 5972 |
#### Beta function <a id="sf.cmath.beta">[[sf.cmath.beta]]</a>
|
| 5973 |
|
| 5974 |
``` cpp
|
| 5975 |
+
floating-point-type beta(floating-point-type x, floating-point-type y);
|
| 5976 |
float betaf(float x, float y);
|
| 5977 |
long double betal(long double x, long double y);
|
| 5978 |
```
|
| 5979 |
|
| 5980 |
*Effects:* These functions compute the beta function of their respective
|
|
|
|
| 5985 |
\text{ ,\quad for $x > 0$,\, $y > 0$,}$$ where x is `x` and y is `y`.
|
| 5986 |
|
| 5987 |
#### Complete elliptic integral of the first kind <a id="sf.cmath.comp.ellint.1">[[sf.cmath.comp.ellint.1]]</a>
|
| 5988 |
|
| 5989 |
``` cpp
|
| 5990 |
+
floating-point-type comp_ellint_1(floating-point-type k);
|
| 5991 |
float comp_ellint_1f(float k);
|
| 5992 |
long double comp_ellint_1l(long double k);
|
| 5993 |
```
|
| 5994 |
|
| 5995 |
*Effects:* These functions compute the complete elliptic integral of the
|
|
|
|
| 6002 |
See also [[sf.cmath.ellint.1]].
|
| 6003 |
|
| 6004 |
#### Complete elliptic integral of the second kind <a id="sf.cmath.comp.ellint.2">[[sf.cmath.comp.ellint.2]]</a>
|
| 6005 |
|
| 6006 |
``` cpp
|
| 6007 |
+
floating-point-type comp_ellint_2(floating-point-type k);
|
| 6008 |
float comp_ellint_2f(float k);
|
| 6009 |
long double comp_ellint_2l(long double k);
|
| 6010 |
```
|
| 6011 |
|
| 6012 |
*Effects:* These functions compute the complete elliptic integral of the
|
|
|
|
| 6019 |
See also [[sf.cmath.ellint.2]].
|
| 6020 |
|
| 6021 |
#### Complete elliptic integral of the third kind <a id="sf.cmath.comp.ellint.3">[[sf.cmath.comp.ellint.3]]</a>
|
| 6022 |
|
| 6023 |
``` cpp
|
| 6024 |
+
floating-point-type comp_ellint_3(floating-point-type k, floating-point-type nu);
|
| 6025 |
float comp_ellint_3f(float k, float nu);
|
| 6026 |
long double comp_ellint_3l(long double k, long double nu);
|
| 6027 |
```
|
| 6028 |
|
| 6029 |
*Effects:* These functions compute the complete elliptic integral of the
|
|
|
|
| 6036 |
See also [[sf.cmath.ellint.3]].
|
| 6037 |
|
| 6038 |
#### Regular modified cylindrical Bessel functions <a id="sf.cmath.cyl.bessel.i">[[sf.cmath.cyl.bessel.i]]</a>
|
| 6039 |
|
| 6040 |
``` cpp
|
| 6041 |
+
floating-point-type cyl_bessel_i(floating-point-type nu, floating-point-type x);
|
| 6042 |
float cyl_bessel_if(float nu, float x);
|
| 6043 |
long double cyl_bessel_il(long double nu, long double x);
|
| 6044 |
```
|
| 6045 |
|
| 6046 |
*Effects:* These functions compute the regular modified cylindrical
|
|
|
|
| 6057 |
See also [[sf.cmath.cyl.bessel.j]].
|
| 6058 |
|
| 6059 |
#### Cylindrical Bessel functions of the first kind <a id="sf.cmath.cyl.bessel.j">[[sf.cmath.cyl.bessel.j]]</a>
|
| 6060 |
|
| 6061 |
``` cpp
|
| 6062 |
+
floating-point-type cyl_bessel_j(floating-point-type nu, floating-point-type x);
|
| 6063 |
float cyl_bessel_jf(float nu, float x);
|
| 6064 |
long double cyl_bessel_jl(long double nu, long double x);
|
| 6065 |
```
|
| 6066 |
|
| 6067 |
*Effects:* These functions compute the cylindrical Bessel functions of
|
|
|
|
| 6075 |
*implementation-defined* if `nu >= 128`.
|
| 6076 |
|
| 6077 |
#### Irregular modified cylindrical Bessel functions <a id="sf.cmath.cyl.bessel.k">[[sf.cmath.cyl.bessel.k]]</a>
|
| 6078 |
|
| 6079 |
``` cpp
|
| 6080 |
+
floating-point-type cyl_bessel_k(floating-point-type nu, floating-point-type x);
|
| 6081 |
float cyl_bessel_kf(float nu, float x);
|
| 6082 |
long double cyl_bessel_kl(long double nu, long double x);
|
| 6083 |
```
|
| 6084 |
|
| 6085 |
*Effects:* These functions compute the irregular modified cylindrical
|
|
|
|
| 6115 |
[[sf.cmath.cyl.neumann]].
|
| 6116 |
|
| 6117 |
#### Cylindrical Neumann functions <a id="sf.cmath.cyl.neumann">[[sf.cmath.cyl.neumann]]</a>
|
| 6118 |
|
| 6119 |
``` cpp
|
| 6120 |
+
floating-point-type cyl_neumann(floating-point-type nu, floating-point-type x);
|
| 6121 |
float cyl_neumannf(float nu, float x);
|
| 6122 |
long double cyl_neumannl(long double nu, long double x);
|
| 6123 |
```
|
| 6124 |
|
| 6125 |
*Effects:* These functions compute the cylindrical Neumann functions,
|
|
|
|
| 6149 |
See also [[sf.cmath.cyl.bessel.j]].
|
| 6150 |
|
| 6151 |
#### Incomplete elliptic integral of the first kind <a id="sf.cmath.ellint.1">[[sf.cmath.ellint.1]]</a>
|
| 6152 |
|
| 6153 |
``` cpp
|
| 6154 |
+
floating-point-type ellint_1(floating-point-type k, floating-point-type phi);
|
| 6155 |
float ellint_1f(float k, float phi);
|
| 6156 |
long double ellint_1l(long double k, long double phi);
|
| 6157 |
```
|
| 6158 |
|
| 6159 |
*Effects:* These functions compute the incomplete elliptic integral of
|
|
|
|
| 6165 |
\text{ ,\quad for $|k| \le 1$,}$$ where k is `k` and φ is `phi`.
|
| 6166 |
|
| 6167 |
#### Incomplete elliptic integral of the second kind <a id="sf.cmath.ellint.2">[[sf.cmath.ellint.2]]</a>
|
| 6168 |
|
| 6169 |
``` cpp
|
| 6170 |
+
floating-point-type ellint_2(floating-point-type k, floating-point-type phi);
|
| 6171 |
float ellint_2f(float k, float phi);
|
| 6172 |
long double ellint_2l(long double k, long double phi);
|
| 6173 |
```
|
| 6174 |
|
| 6175 |
*Effects:* These functions compute the incomplete elliptic integral of
|
|
|
|
| 6181 |
\text{ ,\quad for $|k| \le 1$,}$$ where k is `k` and φ is `phi`.
|
| 6182 |
|
| 6183 |
#### Incomplete elliptic integral of the third kind <a id="sf.cmath.ellint.3">[[sf.cmath.ellint.3]]</a>
|
| 6184 |
|
| 6185 |
``` cpp
|
| 6186 |
+
floating-point-type ellint_3(floating-point-type k, floating-point-type nu,
|
| 6187 |
+
floating-point-type phi);
|
| 6188 |
float ellint_3f(float k, float nu, float phi);
|
| 6189 |
long double ellint_3l(long double k, long double nu, long double phi);
|
| 6190 |
```
|
| 6191 |
|
| 6192 |
*Effects:* These functions compute the incomplete elliptic integral of
|
|
|
|
| 6198 |
where $\nu$ is `nu`, k is `k`, and φ is `phi`.
|
| 6199 |
|
| 6200 |
#### Exponential integral <a id="sf.cmath.expint">[[sf.cmath.expint]]</a>
|
| 6201 |
|
| 6202 |
``` cpp
|
| 6203 |
+
floating-point-type expint(floating-point-type x);
|
| 6204 |
float expintf(float x);
|
| 6205 |
long double expintl(long double x);
|
| 6206 |
```
|
| 6207 |
|
| 6208 |
*Effects:* These functions compute the exponential integral of their
|
|
|
|
| 6215 |
\;$$ where x is `x`.
|
| 6216 |
|
| 6217 |
#### Hermite polynomials <a id="sf.cmath.hermite">[[sf.cmath.hermite]]</a>
|
| 6218 |
|
| 6219 |
``` cpp
|
| 6220 |
+
floating-point-type hermite(unsigned n, floating-point-type x);
|
| 6221 |
float hermitef(unsigned n, float x);
|
| 6222 |
long double hermitel(unsigned n, long double x);
|
| 6223 |
```
|
| 6224 |
|
| 6225 |
*Effects:* These functions compute the Hermite polynomials of their
|
|
|
|
| 6235 |
*implementation-defined* if `n >= 128`.
|
| 6236 |
|
| 6237 |
#### Laguerre polynomials <a id="sf.cmath.laguerre">[[sf.cmath.laguerre]]</a>
|
| 6238 |
|
| 6239 |
``` cpp
|
| 6240 |
+
floating-point-type laguerre(unsigned n, floating-point-type x);
|
| 6241 |
float laguerref(unsigned n, float x);
|
| 6242 |
long double laguerrel(unsigned n, long double x);
|
| 6243 |
```
|
| 6244 |
|
| 6245 |
*Effects:* These functions compute the Laguerre polynomials of their
|
|
|
|
| 6253 |
*implementation-defined* if `n >= 128`.
|
| 6254 |
|
| 6255 |
#### Legendre polynomials <a id="sf.cmath.legendre">[[sf.cmath.legendre]]</a>
|
| 6256 |
|
| 6257 |
``` cpp
|
| 6258 |
+
floating-point-type legendre(unsigned l, floating-point-type x);
|
| 6259 |
float legendref(unsigned l, float x);
|
| 6260 |
long double legendrel(unsigned l, long double x);
|
| 6261 |
```
|
| 6262 |
|
| 6263 |
*Effects:* These functions compute the Legendre polynomials of their
|
|
|
|
| 6272 |
*implementation-defined* if `l >= 128`.
|
| 6273 |
|
| 6274 |
#### Riemann zeta function <a id="sf.cmath.riemann.zeta">[[sf.cmath.riemann.zeta]]</a>
|
| 6275 |
|
| 6276 |
``` cpp
|
| 6277 |
+
floating-point-type riemann_zeta(floating-point-type x);
|
| 6278 |
float riemann_zetaf(float x);
|
| 6279 |
long double riemann_zetal(long double x);
|
| 6280 |
```
|
| 6281 |
|
| 6282 |
*Effects:* These functions compute the Riemann zeta function of their
|
|
|
|
| 6306 |
\;$$ where x is `x`.
|
| 6307 |
|
| 6308 |
#### Spherical Bessel functions of the first kind <a id="sf.cmath.sph.bessel">[[sf.cmath.sph.bessel]]</a>
|
| 6309 |
|
| 6310 |
``` cpp
|
| 6311 |
+
floating-point-type sph_bessel(unsigned n, floating-point-type x);
|
| 6312 |
float sph_besself(unsigned n, float x);
|
| 6313 |
long double sph_bessell(unsigned n, long double x);
|
| 6314 |
```
|
| 6315 |
|
| 6316 |
*Effects:* These functions compute the spherical Bessel functions of the
|
|
|
|
| 6326 |
See also [[sf.cmath.cyl.bessel.j]].
|
| 6327 |
|
| 6328 |
#### Spherical associated Legendre functions <a id="sf.cmath.sph.legendre">[[sf.cmath.sph.legendre]]</a>
|
| 6329 |
|
| 6330 |
``` cpp
|
| 6331 |
+
floating-point-type sph_legendre(unsigned l, unsigned m, floating-point-type theta);
|
| 6332 |
float sph_legendref(unsigned l, unsigned m, float theta);
|
| 6333 |
long double sph_legendrel(unsigned l, unsigned m, long double theta);
|
| 6334 |
```
|
| 6335 |
|
| 6336 |
*Effects:* These functions compute the spherical associated Legendre
|
|
|
|
| 6350 |
See also [[sf.cmath.assoc.legendre]].
|
| 6351 |
|
| 6352 |
#### Spherical Neumann functions <a id="sf.cmath.sph.neumann">[[sf.cmath.sph.neumann]]</a>
|
| 6353 |
|
| 6354 |
``` cpp
|
| 6355 |
+
floating-point-type sph_neumann(unsigned n, floating-point-type x);
|
| 6356 |
float sph_neumannf(unsigned n, float x);
|
| 6357 |
long double sph_neumannl(unsigned n, long double x);
|
| 6358 |
```
|
| 6359 |
|
| 6360 |
*Effects:* These functions compute the spherical Neumann functions, also
|
|
|
|
| 6374 |
|
| 6375 |
### Header `<numbers>` synopsis <a id="numbers.syn">[[numbers.syn]]</a>
|
| 6376 |
|
| 6377 |
``` cpp
|
| 6378 |
namespace std::numbers {
|
| 6379 |
+
template<class T> constexpr T e_v = unspecified;
|
| 6380 |
+
template<class T> constexpr T log2e_v = unspecified;
|
| 6381 |
+
template<class T> constexpr T log10e_v = unspecified;
|
| 6382 |
+
template<class T> constexpr T pi_v = unspecified;
|
| 6383 |
+
template<class T> constexpr T inv_pi_v = unspecified;
|
| 6384 |
+
template<class T> constexpr T inv_sqrtpi_v = unspecified;
|
| 6385 |
+
template<class T> constexpr T ln2_v = unspecified;
|
| 6386 |
+
template<class T> constexpr T ln10_v = unspecified;
|
| 6387 |
+
template<class T> constexpr T sqrt2_v = unspecified;
|
| 6388 |
+
template<class T> constexpr T sqrt3_v = unspecified;
|
| 6389 |
+
template<class T> constexpr T inv_sqrt3_v = unspecified;
|
| 6390 |
+
template<class T> constexpr T egamma_v = unspecified;
|
| 6391 |
+
template<class T> constexpr T phi_v = unspecified;
|
| 6392 |
|
| 6393 |
+
template<floating_point T> constexpr T e_v<T> = see below;
|
| 6394 |
+
template<floating_point T> constexpr T log2e_v<T> = see below;
|
| 6395 |
+
template<floating_point T> constexpr T log10e_v<T> = see below;
|
| 6396 |
+
template<floating_point T> constexpr T pi_v<T> = see below;
|
| 6397 |
+
template<floating_point T> constexpr T inv_pi_v<T> = see below;
|
| 6398 |
+
template<floating_point T> constexpr T inv_sqrtpi_v<T> = see below;
|
| 6399 |
+
template<floating_point T> constexpr T ln2_v<T> = see below;
|
| 6400 |
+
template<floating_point T> constexpr T ln10_v<T> = see below;
|
| 6401 |
+
template<floating_point T> constexpr T sqrt2_v<T> = see below;
|
| 6402 |
+
template<floating_point T> constexpr T sqrt3_v<T> = see below;
|
| 6403 |
+
template<floating_point T> constexpr T inv_sqrt3_v<T> = see below;
|
| 6404 |
+
template<floating_point T> constexpr T egamma_v<T> = see below;
|
| 6405 |
+
template<floating_point T> constexpr T phi_v<T> = see below;
|
| 6406 |
|
| 6407 |
inline constexpr double e = e_v<double>;
|
| 6408 |
inline constexpr double log2e = log2e_v<double>;
|
| 6409 |
inline constexpr double log10e = log10e_v<double>;
|
| 6410 |
inline constexpr double pi = pi_v<double>;
|
|
|
|
| 6438 |
|
| 6439 |
<!-- Link reference definitions -->
|
| 6440 |
[bad.alloc]: support.md#bad.alloc
|
| 6441 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 6442 |
[basic.stc.thread]: basic.md#basic.stc.thread
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6443 |
[c.math]: #c.math
|
| 6444 |
[c.math.abs]: #c.math.abs
|
| 6445 |
[c.math.fpclass]: #c.math.fpclass
|
| 6446 |
[c.math.hypot3]: #c.math.hypot3
|
| 6447 |
[c.math.lerp]: #c.math.lerp
|
| 6448 |
[c.math.rand]: #c.math.rand
|
| 6449 |
[cfenv]: #cfenv
|
| 6450 |
[cfenv.syn]: #cfenv.syn
|
| 6451 |
+
[cfenv.thread]: #cfenv.thread
|
| 6452 |
[class.gslice]: #class.gslice
|
| 6453 |
[class.gslice.overview]: #class.gslice.overview
|
| 6454 |
[class.slice]: #class.slice
|
| 6455 |
[class.slice.overview]: #class.slice.overview
|
| 6456 |
[cmath.syn]: #cmath.syn
|
|
|
|
| 6458 |
[complex]: #complex
|
| 6459 |
[complex.literals]: #complex.literals
|
| 6460 |
[complex.member.ops]: #complex.member.ops
|
| 6461 |
[complex.members]: #complex.members
|
| 6462 |
[complex.numbers]: #complex.numbers
|
| 6463 |
+
[complex.numbers.general]: #complex.numbers.general
|
| 6464 |
[complex.ops]: #complex.ops
|
|
|
|
| 6465 |
[complex.syn]: #complex.syn
|
| 6466 |
[complex.transcendentals]: #complex.transcendentals
|
| 6467 |
[complex.value.ops]: #complex.value.ops
|
| 6468 |
[cons.slice]: #cons.slice
|
| 6469 |
[conv.prom]: expr.md#conv.prom
|
| 6470 |
[cpp.pragma]: cpp.md#cpp.pragma
|
| 6471 |
[cpp17.copyassignable]: #cpp17.copyassignable
|
| 6472 |
[cpp17.copyconstructible]: #cpp17.copyconstructible
|
| 6473 |
[cpp17.equalitycomparable]: #cpp17.equalitycomparable
|
| 6474 |
[dcl.init]: dcl.md#dcl.init
|
|
|
|
| 6475 |
[gslice.access]: #gslice.access
|
| 6476 |
[gslice.array.assign]: #gslice.array.assign
|
| 6477 |
[gslice.array.comp.assign]: #gslice.array.comp.assign
|
| 6478 |
[gslice.array.fill]: #gslice.array.fill
|
| 6479 |
[gslice.cons]: #gslice.cons
|
|
|
|
| 6481 |
[indirect.array.assign]: #indirect.array.assign
|
| 6482 |
[indirect.array.comp.assign]: #indirect.array.comp.assign
|
| 6483 |
[indirect.array.fill]: #indirect.array.fill
|
| 6484 |
[input.iterators]: iterators.md#input.iterators
|
| 6485 |
[input.output]: input.md#input.output
|
|
|
|
| 6486 |
[iostate.flags]: input.md#iostate.flags
|
| 6487 |
[istream.formatted]: input.md#istream.formatted
|
| 6488 |
[iterator.concept.contiguous]: iterators.md#iterator.concept.contiguous
|
| 6489 |
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 6490 |
[library.c]: library.md#library.c
|
|
|
|
| 6499 |
[numeric.requirements]: #numeric.requirements
|
| 6500 |
[numerics]: #numerics
|
| 6501 |
[numerics.general]: #numerics.general
|
| 6502 |
[numerics.summary]: #numerics.summary
|
| 6503 |
[output.iterators]: iterators.md#output.iterators
|
| 6504 |
+
[over.match.general]: over.md#over.match.general
|
| 6505 |
[rand]: #rand
|
| 6506 |
[rand.adapt]: #rand.adapt
|
| 6507 |
[rand.adapt.disc]: #rand.adapt.disc
|
| 6508 |
[rand.adapt.general]: #rand.adapt.general
|
| 6509 |
[rand.adapt.ibits]: #rand.adapt.ibits
|
|
|
|
| 6535 |
[rand.dist.samp.plinear]: #rand.dist.samp.plinear
|
| 6536 |
[rand.dist.uni]: #rand.dist.uni
|
| 6537 |
[rand.dist.uni.int]: #rand.dist.uni.int
|
| 6538 |
[rand.dist.uni.real]: #rand.dist.uni.real
|
| 6539 |
[rand.eng]: #rand.eng
|
| 6540 |
+
[rand.eng.general]: #rand.eng.general
|
| 6541 |
[rand.eng.lcong]: #rand.eng.lcong
|
| 6542 |
[rand.eng.mers]: #rand.eng.mers
|
| 6543 |
[rand.eng.sub]: #rand.eng.sub
|
| 6544 |
+
[rand.general]: #rand.general
|
| 6545 |
[rand.predef]: #rand.predef
|
| 6546 |
[rand.req]: #rand.req
|
| 6547 |
[rand.req.adapt]: #rand.req.adapt
|
| 6548 |
[rand.req.dist]: #rand.req.dist
|
| 6549 |
[rand.req.eng]: #rand.req.eng
|
|
|
|
| 6569 |
[sf.cmath.cyl.neumann]: #sf.cmath.cyl.neumann
|
| 6570 |
[sf.cmath.ellint.1]: #sf.cmath.ellint.1
|
| 6571 |
[sf.cmath.ellint.2]: #sf.cmath.ellint.2
|
| 6572 |
[sf.cmath.ellint.3]: #sf.cmath.ellint.3
|
| 6573 |
[sf.cmath.expint]: #sf.cmath.expint
|
| 6574 |
+
[sf.cmath.general]: #sf.cmath.general
|
| 6575 |
[sf.cmath.hermite]: #sf.cmath.hermite
|
| 6576 |
[sf.cmath.laguerre]: #sf.cmath.laguerre
|
| 6577 |
[sf.cmath.legendre]: #sf.cmath.legendre
|
| 6578 |
[sf.cmath.riemann.zeta]: #sf.cmath.riemann.zeta
|
| 6579 |
[sf.cmath.sph.bessel]: #sf.cmath.sph.bessel
|
|
|
|
| 6593 |
[template.mask.array.overview]: #template.mask.array.overview
|
| 6594 |
[template.slice.array]: #template.slice.array
|
| 6595 |
[template.slice.array.overview]: #template.slice.array.overview
|
| 6596 |
[template.valarray]: #template.valarray
|
| 6597 |
[template.valarray.overview]: #template.valarray.overview
|
| 6598 |
+
[term.literal.type]: basic.md#term.literal.type
|
| 6599 |
[thread.jthread.class]: thread.md#thread.jthread.class
|
| 6600 |
[thread.thread.class]: thread.md#thread.thread.class
|
| 6601 |
[utility.arg.requirements]: library.md#utility.arg.requirements
|
| 6602 |
[valarray.access]: #valarray.access
|
| 6603 |
[valarray.assign]: #valarray.assign
|
|
|
|
| 6616 |
|
| 6617 |
[^1]: In other words, value types. These include arithmetic types,
|
| 6618 |
pointers, the library class `complex`, and instantiations of
|
| 6619 |
`valarray` for value types.
|
| 6620 |
|
| 6621 |
+
[^2]: This constructor (as well as the subsequent corresponding `seed()`
|
| 6622 |
+
function) can be particularly useful to applications requiring a
|
| 6623 |
+
large number of independent random sequences.
|
| 6624 |
+
|
| 6625 |
+
[^3]: The name of this engine refers, in part, to a property of its
|
| 6626 |
period: For properly-selected values of the parameters, the period
|
| 6627 |
is closely related to a large Mersenne prime number.
|
| 6628 |
|
| 6629 |
+
[^4]: The parameter is intended to allow an implementation to
|
| 6630 |
differentiate between different sources of randomness.
|
| 6631 |
|
| 6632 |
+
[^5]: If a device has n states whose respective probabilities are
|
| 6633 |
P₀, …, Pₙ₋₁, the device entropy S is defined as
|
| 6634 |
$S = - \sum_{i=0}^{n-1} P_i \cdot \log P_i$.
|
| 6635 |
|
| 6636 |
+
[^6]: b is introduced to avoid any attempt to produce more bits of
|
| 6637 |
randomness than can be held in `RealType`.
|
| 6638 |
|
| 6639 |
+
[^7]: The distribution corresponding to this probability density
|
| 6640 |
function is also known (with a possible change of variable) as the
|
| 6641 |
Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I
|
| 6642 |
distribution.
|
| 6643 |
|
| 6644 |
+
[^8]: [[implimits]] recommends a minimum number of recursively nested
|
| 6645 |
template instantiations. This requirement thus indirectly suggests a
|
| 6646 |
minimum allowable complexity for valarray expressions.
|
| 6647 |
|
| 6648 |
+
[^9]: The intent is to specify an array template that has the minimum
|
| 6649 |
functionality necessary to address aliasing ambiguities and the
|
| 6650 |
proliferation of temporary objects. Thus, the `valarray` template is
|
| 6651 |
neither a matrix class nor a field class. However, it is a very
|
| 6652 |
useful building block for designing such classes.
|
| 6653 |
|
| 6654 |
+
[^10]: This default constructor is essential, since arrays of `valarray`
|
| 6655 |
+
can be useful. After initialization, the length of an empty array
|
| 6656 |
can be increased with the `resize` member function.
|
| 6657 |
|
| 6658 |
+
[^11]: This constructor is the preferred method for converting a C array
|
| 6659 |
to a `valarray` object.
|
| 6660 |
|
| 6661 |
+
[^12]: This copy constructor creates a distinct array rather than an
|
| 6662 |
alias. Implementations in which arrays share storage are permitted,
|
| 6663 |
but they would need to implement a copy-on-reference mechanism to
|
| 6664 |
ensure that arrays are conceptually distinct.
|
| 6665 |
|
| 6666 |
+
[^13]: BLAS stands for *Basic Linear Algebra Subprograms*. C++ programs
|
| 6667 |
+
can instantiate this class. See, for example, Dongarra, Du Croz,
|
| 6668 |
Duff, and Hammerling: *A set of Level 3 Basic Linear Algebra
|
| 6669 |
Subprograms*; Technical Report MCS-P1-0888, Argonne National
|
| 6670 |
Laboratory (USA), Mathematics and Computer Science Division, August,
|
| 6671 |
1988.
|
| 6672 |
|
| 6673 |
+
[^14]: A mathematical function is mathematically defined for a given set
|
| 6674 |
of argument values (a) if it is explicitly defined for that set of
|
| 6675 |
argument values, or (b) if its limiting value exists and does not
|
| 6676 |
depend on the direction of approach.
|