diff options
-rw-r--r-- | libstdc++-v3/ChangeLog | 24 | ||||
-rw-r--r-- | libstdc++-v3/include/tr1/random | 350 | ||||
-rw-r--r-- | libstdc++-v3/include/tr1/random.tcc | 373 |
3 files changed, 641 insertions, 106 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6979a43..359e79d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,27 @@ +2006-06-25 Paolo Carlini <pcarlini@suse.de> + + * include/tr1/random (operator<<(std::basic_ostream<>&, + const linear_congruential<>&), operator>>(std::basic_istream<>&, + linear_congruential<>&), operator<<(std::basic_ostream<>&, + const mersenne_twister<>&), operator>>(std::basic_istream<>&, + mersenne_twister<>&), operator<<(std::basic_ostream<>&, + const subtract_with_carry<>&), operator>>(std::basic_istream<>&, + subtract_with_carry<>&), operator<<(std::basic_ostream<>&, + const discard_block<>&), operator>>(std::basic_istream<>&, + discard_block<>&), operator<<(std::basic_ostream<>&, + const xor_combine<>&), operator>>(std::basic_istream<>&, + xor_combine<>&), operator<<(std::basic_ostream<>&, + const uniform_int<>&), operator>>(std::basic_istream<>&, + uniform_int<>&), operator<<(std::basic_ostream<>&, + const bernoulli_distribution&), operator<<(std::basic_ostream<>&, + const geometric_distribution<>&), operator<<(std::basic_ostream<>&, + const uniform_real<>&), operator>>(std::basic_istream<>&, + uniform_real<>&), operator<<(std::basic_ostream<>&, + const exponential_distribution<>&), operator<<(std::basic_ostream<>&, + const normal_distribution<>&), operator>>(std::basic_istream<>&, + normal_distribution<>&)): Redo per TR1 specs; move out of line... + * include/tr1/random.tcc: ... here. + 2006-06-24 Paolo Carlini <pcarlini@suse.de> * include/tr1/random (class normal_distribution<>): Add. diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random index 7eb8f67..f1a3ab2 100644 --- a/libstdc++-v3/include/tr1/random +++ b/libstdc++-v3/include/tr1/random @@ -288,6 +288,21 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * The size of the state is @f$ 1 @f$. */ template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + class linear_congruential; + + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const linear_congruential<_UIntType, __a, __c, __m>& __lcr); + + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + linear_congruential<_UIntType, __a, __c, __m>& __lcr); + + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> class linear_congruential { __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) @@ -394,14 +409,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * Writes the textual representation of the state x(i) of x to @p __os. * * @param __os The output stream. - * @param __lcr A linear_congruential random number generator. + * @param __lcr A % linear_congruential random number generator. * @returns __os. */ - template<typename _CharT, typename _Traits> + template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1, + _UIntType1 __m1, + typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const linear_congruential& __lcr) - { return __os << __lcr._M_x; } + const linear_congruential<_UIntType1, __a1, __c1, + __m1>& __lcr); /** * Sets the state of the engine by reading its textual @@ -413,14 +430,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @p __is. * * @param __is The input stream. - * @param __lcr A linear_congruential random number generator. + * @param __lcr A % linear_congruential random number generator. * @returns __is. */ - template<typename _CharT, typename _Traits> + template<class _UIntType1, _UIntType1 __a1, _UIntType1 __c1, + _UIntType1 __m1, + typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - linear_congruential& __lcr) - { return __is >> __lcr._M_x; } + linear_congruential<_UIntType1, __a1, __c1, __m1>& __lcr); private: template<class _Gen> @@ -475,6 +493,29 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template<class _UIntType, int __w, int __n, int __m, int __r, _UIntType __a, int __u, int __s, _UIntType __b, int __t, _UIntType __c, int __l> + class mersenne_twister; + + template<class _UIntType, int __w, int __n, int __m, int __r, + _UIntType __a, int __u, int __s, _UIntType __b, int __t, + _UIntType __c, int __l, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x); + + template<class _UIntType, int __w, int __n, int __m, int __r, + _UIntType __a, int __u, int __s, _UIntType __b, int __t, + _UIntType __c, int __l, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x); + + template<class _UIntType, int __w, int __n, int __m, int __r, + _UIntType __a, int __u, int __s, _UIntType __b, int __t, + _UIntType __c, int __l> class mersenne_twister { __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) @@ -571,15 +612,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<class _UIntType1, int __w1, int __n1, int __m1, int __r1, + _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1, + _UIntType1 __c1, int __l1, + typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const mersenne_twister& __x) - { - std::copy(__x._M_x, __x._M_x + state_size, - std::ostream_iterator<_UIntType>(__os, " ")); - return __os; - } + const mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); /** * Extracts the current state of a % mersenne_twister random number @@ -591,15 +631,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<class _UIntType1, int __w1, int __n1, int __m1, int __r1, + _UIntType1 __a1, int __u1, int __s1, _UIntType1 __b1, int __t1, + _UIntType1 __c1, int __l1, + typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - mersenne_twister& __x) - { - for (int __i = 0; __i < state_size; ++__i) - __is >> __x._M_x[__i]; - return __is; - } + mersenne_twister<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); private: template<class _Gen> @@ -654,6 +693,21 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @endif */ template<typename _IntType, _IntType __m, int __s, int __r> + class subtract_with_carry; + + template<typename _IntType, _IntType __m, int __s, int __r, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry<_IntType, __m, __s, __r>& __x); + + template<typename _IntType, _IntType __m, int __s, int __r, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry<_IntType, __m, __s, __r>& __x); + + template<typename _IntType, _IntType __m, int __s, int __r> class subtract_with_carry { __glibcxx_class_requires(_IntType, _IntegerConcept) @@ -780,15 +834,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<typename _IntType1, _IntType1 __m1, int __s1, int __r1, + typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry& __x) - { - std::copy(__x._M_x, __x._M_x + long_lag, - std::ostream_iterator<_IntType>(__os, " ")); - return __os << __x._M_carry; - } + const subtract_with_carry<_IntType1, __m1, __s1, + __r1>& __x); /** * Extracts the current state of a % subtract_with_carry random number @@ -800,16 +851,11 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<typename _IntType1, _IntType1 __m1, int __s1, int __r1, + typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry& __x) - { - for (int __i = 0; __i < long_lag; ++__i) - __is >> __x._M_x[__i]; - __is >> __x._M_carry; - return __is; - } + subtract_with_carry<_IntType1, __m1, __s1, __r1>& __x); private: template<class _Gen> @@ -835,6 +881,22 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * 0 <= @p __r <= @p __p */ template<class _UniformRandomNumberGenerator, int __p, int __r> + class discard_block; + + template<class _UniformRandomNumberGenerator, int __p, int __r, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block<_UniformRandomNumberGenerator, + __p, __r>& __x); + + template<class _UniformRandomNumberGenerator, int __p, int __r, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block<_UniformRandomNumberGenerator, __p, __r>& __x); + + template<class _UniformRandomNumberGenerator, int __p, int __r> class discard_block { // __glibcxx_class_requires(typename base_type::result_type, @@ -974,11 +1036,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<class _UniformRandomNumberGenerator1, int __p1, int __r1, + typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const discard_block& __x) - { return __os << __x._M_b << " " << __x._M_n; } + const discard_block<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); /** * Extracts the current state of a % subtract_with_carry random number @@ -990,11 +1053,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<class _UniformRandomNumberGenerator1, int __p1, int __r1, + typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - discard_block& __x) - { return __is >> __x._M_b >> __x._M_n; } + discard_block<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); private: base_type _M_b; @@ -1027,6 +1091,26 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) */ template<class _UniformRandomNumberGenerator1, int __s1, class _UniformRandomNumberGenerator2, int __s2> + class xor_combine; + + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x); + + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x); + + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2> class xor_combine { // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1:: @@ -1146,11 +1230,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<class _UniformRandomNumberGenerator11, int __s11, + class _UniformRandomNumberGenerator21, int __s21, + typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const xor_combine& __x) - { return __os << __x.base1() << " " << __x.base2(); } + const xor_combine<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); /** * Extracts the current state of a %xor_combine random number @@ -1162,11 +1248,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The input stream with the state of @p __x extracted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<class _UniformRandomNumberGenerator11, int __s11, + class _UniformRandomNumberGenerator21, int __s21, + typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - xor_combine& __x) - { return __is >> __x._M_b1 >> __x._M_b2; } + xor_combine<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); private: base1_type _M_b1; @@ -1283,6 +1371,19 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * probability throughout the range. */ template<typename _IntType = int> + class uniform_int; + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType>& __x); + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType>& __x); + + template<typename _IntType> class uniform_int { __glibcxx_class_requires(_IntType, _IntegerConcept) @@ -1355,25 +1456,24 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<typename _IntType1, typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_int& __x) - { return __os << __x.min() << " " << __x.max(); } + const uniform_int<_IntType1>& __x); /** * Extracts a %unform_int random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %uniform_int random number generator engine. + * @param __x A %uniform_int random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ - template<typename _CharT, typename _Traits> + template<typename _IntType1, typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, uniform_int& __u) - { return __is >> __u._M_min >> __u._M_max; } + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType1>& __x); private: _IntType _M_min; @@ -1387,6 +1487,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * Generates a sequence of true and false values with likelihood @f$ p @f$ * that true will come up and @f$ (1 - p) @f$ that false will appear. */ + class bernoulli_distribution; + + template<typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x); + class bernoulli_distribution { public: @@ -1447,23 +1554,22 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template<typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const bernoulli_distribution& __x) - { return __os << __x.p(); } + const bernoulli_distribution& __x); /** * Extracts a %bernoulli_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %bernoulli_distribution random number generator engine. + * @param __x A %bernoulli_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ template<typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - bernoulli_distribution& __u) - { return __is >> __u._M_p; } + bernoulli_distribution& __x) + { return __is >> __x._M_p; } protected: double _M_p; @@ -1478,6 +1584,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * distribution. */ template<typename _IntType = int, typename _RealType = double> + class geometric_distribution; + + template<typename _IntType, typename _RealType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType, _RealType>& __x); + + template<typename _IntType, typename _RealType> class geometric_distribution { public: @@ -1519,28 +1634,28 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<typename _IntType1, typename _RealType1, + typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const geometric_distribution& __x) - { return __os << __x.p(); } + const geometric_distribution<_IntType1, _RealType1>& __x); /** * Extracts a %geometric_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %geometric_distribution random number generator engine. + * @param __x A %geometric_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ template<typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - geometric_distribution& __u) + geometric_distribution& __x) { - __is >> __u._M_p; - __u._M_log_p = std::log(__u._M_p); + __is >> __x._M_p; + __x._M_log_p = std::log(__x._M_p); return __is; } @@ -1565,6 +1680,19 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * deliver number in the range [0, 1). */ template<typename _RealType = double> + class uniform_real; + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real<_RealType>& __x); + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real<_RealType>& __x); + + template<typename _RealType> class uniform_real { public: @@ -1613,26 +1741,24 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<typename _RealType1, typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_real& __x) - { return __os << __x.min() << " " << __x.max(); } + const uniform_real<_RealType1>& __x); /** * Extracts a %unform_real random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %uniform_real random number generator engine. + * @param __x A %uniform_real random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ - template<typename _CharT, typename _Traits> + template<typename _RealType1, typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_real& __u) - { return __is >> __u._M_min >> __u._M_max; } + uniform_real<_RealType1>& __x); protected: _RealType _M_min; @@ -1656,6 +1782,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * </table> */ template<typename _RealType = double> + class exponential_distribution; + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x); + + template<typename _RealType> class exponential_distribution { public: @@ -1705,26 +1839,25 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<typename _RealType1, typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const exponential_distribution& __x) - { return __os << __x.lambda(); } + const exponential_distribution<_RealType1>& __x); /** * Extracts a %exponential_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %exponential_distribution random number generator engine. + * @param __x A %exponential_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ template<typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - exponential_distribution& __u) - { return __is >> __u._M_lambda; } + exponential_distribution& __x) + { return __is >> __x._M_lambda; } private: result_type _M_lambda; @@ -1739,6 +1872,19 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$. */ template<typename _RealType = double> + class normal_distribution; + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType>& __x); + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType>& __x); + + template<typename _RealType> class normal_distribution { public: @@ -1794,32 +1940,24 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * @returns The output stream with the state of @p __x inserted or in * an error state. */ - template<typename _CharT, typename _Traits> + template<typename _RealType1, typename _CharT, typename _Traits> friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const normal_distribution& __x) - { - return __os << __x.mean() << " " << __x.sigma() - << " " << __x._M_saved << " " << __x._M_saved_available; - } + const normal_distribution<_RealType1>& __x); /** * Extracts a %normal_distribution random number distribution - * @p __u from the input stream @p __is. + * @p __x from the input stream @p __is. * * @param __is An input stream. - * @param __u A %normal_distribution random number generator engine. + * @param __x A %normal_distribution random number generator engine. * - * @returns The input stream with @p __u extracted or in an error state. + * @returns The input stream with @p __x extracted or in an error state. */ - template<typename _CharT, typename _Traits> + template<typename _RealType1, typename _CharT, typename _Traits> friend std::basic_istream<_CharT, _Traits>& operator>>(std::basic_istream<_CharT, _Traits>& __is, - normal_distribution& __u) - { - return __is >> __u._M_mean >> __u._M_sigma - >> __u._M_saved >> __u._M_saved_available; - } + normal_distribution<_RealType1>& __x); private: result_type _M_mean; diff --git a/libstdc++-v3/include/tr1/random.tcc b/libstdc++-v3/include/tr1/random.tcc index d4f2464..562ea9e 100644 --- a/libstdc++-v3/include/tr1/random.tcc +++ b/libstdc++-v3/include/tr1/random.tcc @@ -94,6 +94,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) __mod(_Tp __x) { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); } + // See N1822. + template<typename _RealType> + struct _Max_digits10 + { + static const std::streamsize __value = + 2 + std::numeric_limits<_RealType>::digits * 3010/10000; + }; + } // namespace _Private @@ -167,6 +175,40 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return _M_x; } + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const linear_congruential<_UIntType, __a, __c, __m>& __lcr) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__os.widen(' ')); + + __os << __lcr._M_x; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + linear_congruential<_UIntType, __a, __c, __m>& __lcr) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec); + + __is >> __lcr._M_x; + + __is.flags(__flags); + return __is; + } + template<class _UIntType, int __w, int __n, int __m, int __r, _UIntType __a, int __u, int __s, @@ -255,6 +297,50 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return __z; } + template<class _UIntType, int __w, int __n, int __m, int __r, + _UIntType __a, int __u, int __s, _UIntType __b, int __t, + _UIntType __c, int __l, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __n - 1; ++__i) + __os << __x._M_x[__i] << __space; + __os << __x._M_x[__n - 1]; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<class _UIntType, int __w, int __n, int __m, int __r, + _UIntType __a, int __u, int __s, _UIntType __b, int __t, + _UIntType __c, int __l, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister<_UIntType, __w, __n, __m, + __r, __a, __u, __s, __b, __t, __c, __l>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + for (int __i = 0; __i < __n; ++__i) + __is >> __x._M_x[__i]; + + __is.flags(__flags); + return __is; + } + template<typename _IntType, _IntType __m, int __s, int __r> void @@ -332,6 +418,45 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return __xi; } + template<typename _IntType, _IntType __m, int __s, int __r, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry<_IntType, __m, __s, __r>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __r; ++__i) + __os << __x._M_x[__i] << __space; + __os << __x._M_carry; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<typename _IntType, _IntType __m, int __s, int __r, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry<_IntType, __m, __s, __r>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + for (int __i = 0; __i < __r; ++__i) + __is >> __x._M_x[__i]; + __is >> __x._M_carry; + + __is.flags(__flags); + return __is; + } + template<class _UniformRandomNumberGenerator, int __p, int __r> typename discard_block<_UniformRandomNumberGenerator, @@ -352,6 +477,215 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return _M_b(); } + template<class _UniformRandomNumberGenerator, int __p, int __r, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block<_UniformRandomNumberGenerator, + __p, __r>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + __os << __x._M_b << __space << __x._M_n; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<class _UniformRandomNumberGenerator, int __p, int __r, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block<_UniformRandomNumberGenerator, __p, __r>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + __is >> __x._M_b >> __x._M_n; + + __is.flags(__flags); + return __is; + } + + + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::dec | std::ios_base::fixed + | std::ios_base::left); + __os.fill(__space); + + __os << __x.base1() << __space << __x.base2(); + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::skipws); + + __is >> __x._M_b1 >> __x._M_b2; + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__space); + + __os << __x.min() << __space << __x.max(); + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + __is >> __x._M_min >> __x._M_max; + + __is.flags(__flags); + return __is; + } + + + template<typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(_Private::_Max_digits10<double>::__value); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template<typename _IntType, typename _RealType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType, _RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__space); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.min() << __space << __x.max(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::skipws); + + __is >> __x._M_min >> __x._M_max; + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.lambda(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + /** * Classic Box-Muller method. @@ -394,5 +728,44 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) return __ret * _M_sigma + _M_mean; } + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(std::ios_base::scientific | std::ios_base::left); + __os.fill(__space); + __os.precision(_Private::_Max_digits10<_RealType>::__value); + + __os << __x.mean() << __space + << __x.sigma() << __space + << __x._M_saved << __space + << __x._M_saved_available; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType>& __x) + { + const std::ios_base::fmtflags __flags = __is.flags(); + __is.flags(std::ios_base::dec | std::ios_base::skipws); + + __is >> __x._M_mean >> __x._M_sigma + >> __x._M_saved >> __x._M_saved_available; + + __is.flags(__flags); + return __is; + } + _GLIBCXX_END_NAMESPACE } |