diff options
165 files changed, 19014 insertions, 4033 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 61b2c0594a2..23954fbe883 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,6 +1,324 @@ +2009-04-02 Benjamin Kosnik <bkoz@redhat.com> + + * testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc: + Change to mersenne_twister_engine, add same defaults as + mersenne_twister_engine/cons/default.cc. + * testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc: Same. + + * include/bits/random.tcc (seed_seq::seed_seq): Uglify parameter + to __il. + * include/bits/random.h (mersenne_twister_engine): Qualify + _ShiftMin1 with namespace __detail. + (__detail::_ShiftMin1): Use __gnu_cxx::__numeric_traits::max until + constexpr std::numeric_limits::max() can be used. + (mersenne_twister_engine): Split apart static asserts into one + assert per message. Temporarily disable the last three. + +2009-04-02 Edward Smith-Rowland <3dw4rd@verizon.net> + + * include/Makefile.am: Update to N2836. Modified for new random headers. + * include/Makefile.in: Ditto. + * include/tr1_impl/random: Moved to tr1/random.h + * include/tr1_impl/random.tcc: Moved to tr1 + * include/tr1/random: Just point to moved tr1 random headers. + * include/tr1/random.tcc: Moved from tr1_impl. + * include/tr1/random.h: Moved from tr1_impl/random. + * include/std/random: Modified to point to std random headers. + * include/bits/random.tcc: New implementation of std random facilities. + * include/bits/random.h: Ditto. + * testsuite/26_numerics/headers/random/std_c++0x_neg.cc: Changed. + * testsuite/26_numerics/random/linear_congruential_engine/cons/ + seed1.cc: New. + * testsuite/26_numerics/random/linear_congruential_engine/cons/ + seed2.cc: New. + * testsuite/26_numerics/random/linear_congruential_engine/cons/ + default.cc: New. + * testsuite/26_numerics/random/linear_congruential_engine/requirements/ + non_uint_neg.cc: New. + * testsuite/26_numerics/random/linear_congruential_engine/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/linear_congruential_engine/operators/ + equal.cc: New. + * testsuite/26_numerics/random/linear_congruential_engine/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/mersenne_twister_engine/cons/ + seed1.cc: New. + * testsuite/26_numerics/random/mersenne_twister_engine/cons/ + seed2.cc: New. + * testsuite/26_numerics/random/mersenne_twister_engine/cons/ + default.cc: New. + * testsuite/26_numerics/random/mersenne_twister_engine/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/mersenne_twister_engine/operators/ + equal.cc: New. + * testsuite/26_numerics/random/mersenne_twister_engine/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/subtract_with_carry_engine/cons/ + seed1.cc: New. + * testsuite/26_numerics/random/subtract_with_carry_engine/cons/ + seed2.cc: New. + * testsuite/26_numerics/random/subtract_with_carry_engine/cons/ + default.cc: New. + * testsuite/26_numerics/random/subtract_with_carry_engine/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/subtract_with_carry_engine/operators/ + equal.cc: New. + * testsuite/26_numerics/random/subtract_with_carry_engine/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/discard_block_engine/cons/ + base_move.cc: New. + * testsuite/26_numerics/random/discard_block_engine/cons/ + seed1.cc: New. + * testsuite/26_numerics/random/discard_block_engine/cons/ + seed2.cc: New. + * testsuite/26_numerics/random/discard_block_engine/cons/ + base_copy.cc: New. + * testsuite/26_numerics/random/discard_block_engine/cons/ + default.cc: New. + * testsuite/26_numerics/random/discard_block_engine/cons/ + seed_seq.cc: New. + * testsuite/26_numerics/random/discard_block_engine/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/discard_block_engine/operators/ + equal.cc: New. + * testsuite/26_numerics/random/discard_block_engine/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/cons/ + base_move.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/cons/ + seed1.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/cons/ + seed2.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/cons/ + base_copy.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/cons/ + default.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/cons/ + seed_seq.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/operators/ + equal.cc: New. + * testsuite/26_numerics/random/independent_bits_engine/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/cons/ + base_move.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/cons/ + seed1.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/cons/ + seed2.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/cons/ + base_copy.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/cons/ + default.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/cons/ + seed_seq.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/operators/ + equal.cc: New. + * testsuite/26_numerics/random/shuffle_order_engine/operators/ + serialize.cc + * testsuite/26_numerics/random/mt19937.cc: New. + * testsuite/26_numerics/random/mt19937_64.cc: New. + * testsuite/26_numerics/random/minstd_rand.cc: New. + * testsuite/26_numerics/random/minstd_rand0.cc: New. + * testsuite/26_numerics/random/ranlux24_base.cc: New. + * testsuite/26_numerics/random/ranlux48_base.cc: New. + * testsuite/26_numerics/random/ranlux24.cc: New. + * testsuite/26_numerics/random/ranlux48.cc: New. + * testsuite/26_numerics/random/knuth_b.cc: New. + * testsuite/26_numerics/random/default_random_engine.cc: New. + * testsuite/26_numerics/random/chi_squared_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/chi_squared_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/chi_squared_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/chi_squared_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/normal_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/normal_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/normal_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/normal_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/seed_seq/cons/range.cc: New. + * testsuite/26_numerics/random/seed_seq/cons/default.cc: New. + * testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc: New. + * testsuite/26_numerics/random/uniform_int_distribution/cons/ + parms_neg.cc: New. + * testsuite/26_numerics/random/uniform_int_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/uniform_int_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/uniform_int_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/uniform_int_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/uniform_real_distribution/cons/ + parms_neg.cc: New. + * testsuite/26_numerics/random/uniform_real_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/uniform_real_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/uniform_real_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/uniform_real_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/poisson_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/poisson_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/poisson_distribution/requirements/ + typedefs.cc + * testsuite/26_numerics/random/poisson_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/bernoulli_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/bernoulli_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/bernoulli_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/bernoulli_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/discrete_distribution/cons/ + range.cc: New. + * testsuite/26_numerics/random/discrete_distribution/cons/ + initlist.cc: New. + * testsuite/26_numerics/random/discrete_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/discrete_distribution/cons/ + num_xbound_fun.cc: New. + * testsuite/26_numerics/random/discrete_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/discrete_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/weibull_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/weibull_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/weibull_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/weibull_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/negative_binomial_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/negative_binomial_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/negative_binomial_distribution/ + requirements/typedefs.cc: New. + * testsuite/26_numerics/random/negative_binomial_distribution/ + operators/serialize.cc: New. + * testsuite/26_numerics/random/cauchy_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/cauchy_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/cauchy_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/cauchy_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/gamma_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/gamma_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/gamma_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/gamma_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/fisher_f_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/fisher_f_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/fisher_f_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/fisher_f_distribution/operators/ + serialize.cc: New. + + * testsuite/26_numerics/random/exponential_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/exponential_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/exponential_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/exponential_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/lognormal_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/lognormal_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/lognormal_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/lognormal_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/binomial_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/binomial_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/binomial_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/binomial_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/random_device/cons/ + token.cc: New. + * testsuite/26_numerics/random/random_device/cons/ + default.cc: New. + * testsuite/26_numerics/random/random_device/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/extreme_value_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/extreme_value_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/extreme_value_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/extreme_value_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/piecewise_linear_distribution/cons/ + range.cc: New. + * testsuite/26_numerics/random/piecewise_linear_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/piecewise_linear_distribution/cons/ + num_xbound_fun.cc: New. + * testsuite/26_numerics/random/piecewise_linear_distribution/cons/ + initlist_fun.cc: New. + * testsuite/26_numerics/random/piecewise_linear_distribution/ + requirements/typedefs.cc: New. + * testsuite/26_numerics/random/piecewise_linear_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/student_t_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/student_t_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/student_t_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/student_t_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/geometric_distribution/cons/ + parms.cc: New. + * testsuite/26_numerics/random/geometric_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/geometric_distribution/requirements/ + typedefs.cc: New. + * testsuite/26_numerics/random/geometric_distribution/operators/ + serialize.cc: New. + * testsuite/26_numerics/random/piecewise_constant_distribution/cons/ + range.cc: New. + * testsuite/26_numerics/random/piecewise_constant_distribution/cons/ + default.cc: New. + * testsuite/26_numerics/random/piecewise_constant_distribution/cons/ + num_xbound_fun.cc: New. + * testsuite/26_numerics/random/piecewise_constant_distribution/cons/ + initlist_fun.cc: New. + * testsuite/26_numerics/random/piecewise_constant_distribution/ + requirements/typedefs.cc: New. + * testsuite/26_numerics/random/piecewise_constant_distribution/ + operators/serialize.cc: New. + 2009-04-02 Dodji Seketeli <dodji@redhat.com> - * include/ext/bitmap_allocator.h: the typedefs should be made public + * include/ext/bitmap_allocator.h: The typedefs should be made public if we want them to be accessible. This has been revealed by the patch that fixes PR c++/26693 in g++. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 5205e704d92..6b481ce3e07 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -116,6 +116,8 @@ bits_headers = \ ${bits_srcdir}/ostream.tcc \ ${bits_srcdir}/ostream_insert.h \ ${bits_srcdir}/postypes.h \ + ${bits_srcdir}/random.h \ + ${bits_srcdir}/random.tcc \ ${bits_srcdir}/stream_iterator.h \ ${bits_srcdir}/streambuf_iterator.h \ ${bits_srcdir}/shared_ptr.h \ @@ -570,6 +572,8 @@ tr1_headers = \ ${tr1_srcdir}/poly_laguerre.tcc \ ${tr1_srcdir}/legendre_function.tcc \ ${tr1_srcdir}/random \ + ${tr1_srcdir}/random.h \ + ${tr1_srcdir}/random.tcc \ ${tr1_srcdir}/regex \ ${tr1_srcdir}/riemann_zeta.tcc \ ${tr1_srcdir}/shared_ptr.h \ @@ -608,8 +612,6 @@ tr1_impl_headers = \ ${tr1_impl_srcdir}/functional_hash.h \ ${tr1_impl_srcdir}/hashtable \ ${tr1_impl_srcdir}/hashtable_policy.h \ - ${tr1_impl_srcdir}/random \ - ${tr1_impl_srcdir}/random.tcc \ ${tr1_impl_srcdir}/regex \ ${tr1_impl_srcdir}/type_traits \ ${tr1_impl_srcdir}/unordered_map \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index ae85f7eabe8..c1ad2d3dd57 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -381,6 +381,8 @@ bits_headers = \ ${bits_srcdir}/ostream.tcc \ ${bits_srcdir}/ostream_insert.h \ ${bits_srcdir}/postypes.h \ + ${bits_srcdir}/random.h \ + ${bits_srcdir}/random.tcc \ ${bits_srcdir}/stream_iterator.h \ ${bits_srcdir}/streambuf_iterator.h \ ${bits_srcdir}/shared_ptr.h \ @@ -833,6 +835,8 @@ tr1_headers = \ ${tr1_srcdir}/poly_laguerre.tcc \ ${tr1_srcdir}/legendre_function.tcc \ ${tr1_srcdir}/random \ + ${tr1_srcdir}/random.h \ + ${tr1_srcdir}/random.tcc \ ${tr1_srcdir}/regex \ ${tr1_srcdir}/riemann_zeta.tcc \ ${tr1_srcdir}/shared_ptr.h \ @@ -870,8 +874,6 @@ tr1_impl_headers = \ ${tr1_impl_srcdir}/functional_hash.h \ ${tr1_impl_srcdir}/hashtable \ ${tr1_impl_srcdir}/hashtable_policy.h \ - ${tr1_impl_srcdir}/random \ - ${tr1_impl_srcdir}/random.tcc \ ${tr1_impl_srcdir}/regex \ ${tr1_impl_srcdir}/type_traits \ ${tr1_impl_srcdir}/unordered_map \ diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h new file mode 100644 index 00000000000..ad64a90a681 --- /dev/null +++ b/libstdc++-v3/include/bits/random.h @@ -0,0 +1,4940 @@ +// random number generation -*- C++ -*- + +// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** + * @file bits/random.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#include <vector> + +namespace std +{ + + // [26.4] Random number generation + + /** + * @addtogroup std_random Random Number Generation + * A facility for generating random numbers on selected distributions. + * @{ + */ + + /** + * @brief A function template for converting the output of a (integral) + * uniform random number generator to a floatng point result in the range + * [0-1). + */ + template<typename _RealType, size_t __bits, + typename _UniformRandomNumberGenerator> + _RealType + generate_canonical(_UniformRandomNumberGenerator& __g); + + class seed_seq; + + /* + * Implementation-space details. + */ + namespace __detail + { + template<typename _UIntType, size_t __w, + bool = __w < static_cast<size_t>(std::numeric_limits<_UIntType>::digits)> + struct _Shift + { static const _UIntType __value = 0; }; + + template<typename _UIntType, size_t __w> + struct _Shift<_UIntType, __w, true> + { static const _UIntType __value = _UIntType(1) << __w; }; + + // XXX need constexpr + template<typename _UIntType, size_t __w, + bool = __w <static_cast<size_t>(std::numeric_limits<_UIntType>::digits)> + struct _ShiftMin1 + { static const _UIntType __value = __gnu_cxx::__numeric_traits<_UIntType>::max; }; + + template<typename _UIntType, size_t __w> + struct _ShiftMin1<_UIntType, __w, true> + { static const _UIntType __value = _UIntType(1) << __w - _UIntType(1); }; + + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool> + struct _Mod; + + // Dispatch based on modulus value to prevent divide-by-zero compile-time + // errors when m == 0. + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m> + inline _Tp + __mod(_Tp __x) + { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); } + + typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4), + unsigned, unsigned long>::__type _UInt32Type; + + /* + * An adaptor class for converting the output of any Generator into + * the input for a specific Distribution. + */ + template<typename _Engine, typename _DInputType> + struct _Adaptor + { + + public: + _Adaptor(_Engine& __g) + : _M_g(__g) { } + + _DInputType + min() const + { + if (is_integral<_DInputType>::value) + return _M_g.min(); + else + return _DInputType(0); + } + + _DInputType + max() const + { + if (is_integral<_DInputType>::value) + return _M_g.max(); + else + return _DInputType(1); + } + + /* + * Converts a value generated by the adapted random number generator + * into a value in the input domain for the dependent random number + * distribution. + * + * Because the type traits are compile time constants only the + * appropriate clause of the if statements will actually be emitted + * by the compiler. + */ + _DInputType + operator()() + { + if (is_integral<_DInputType>::value) + return _M_g(); + else + return generate_canonical<_DInputType, + numeric_limits<_DInputType>::digits, + _Engine>(_M_g); + } + + private: + _Engine& _M_g; + }; + } // namespace __detail + + /** + * @addtogroup std_random_generators Random Number Generators + * @ingroup std_random + * + * These classes define objects which provide random or pseudorandom + * numbers, either from a discrete or a continuous interval. The + * random number generator supplied as a part of this library are + * all uniform random number generators which provide a sequence of + * random number uniformly distributed over their range. + * + * A number generator is a function object with an operator() that + * takes zero arguments and returns a number. + * + * A compliant random number generator must satisfy the following + * requirements. <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Random Number Generator Requirements</caption> + * <tr><td>To be documented.</td></tr> </table> + * + * @{ + */ + + /** + * @brief A model of a linear congruential random number generator. + * + * A random number generator that produces pseudorandom numbers using the + * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$. + * + * The template parameter @p _UIntType must be an unsigned integral type + * large enough to store values up to (__m-1). If the template parameter + * @p __m is 0, the modulus @p __m used is + * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template + * parameters @p __a and @p __c must be less than @p __m. + * + * The size of the state is @f$ 1 @f$. + */ + template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + class linear_congruential_engine + { + __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) + static_assert(__m == 0 || (__a < __m && __c < __m), + "template arguments out of bounds" + " in linear_congruential_engine"); + + public: + /** The type of the generated random value. */ + typedef _UIntType result_type; + + /** The multiplier. */ + static const result_type multiplier = __a; + /** An increment. */ + static const result_type increment = __c; + /** The modulus. */ + static const result_type modulus = __m; + static const result_type default_seed = 1UL; + + /** + * @brief Constructs a %linear_congruential_engine random number + * generator engine with seed @p __s. The default seed value + * is 1. + * + * @param __s The initial seed value. + */ + explicit + linear_congruential_engine(result_type __s = default_seed) + { this->seed(__s); } + + /** + * @brief Constructs a %linear_congruential_engine random number + * generator engine seeded from the seed sequence @p __q. + * + * @param __q the seed sequence. + */ + explicit + linear_congruential_engine(seed_seq& __q) + { this->seed(__q); } + + /** + * @brief Reseeds the %linear_congruential_engine random number generator + * engine sequence to the seed @g __s. + * + * @param __s The new seed. + */ + void + seed(result_type __s = default_seed); + + /** + * @brief Reseeds the %linear_congruential_engine random number generator + * engine + * sequence using values from the seed sequence @p __q. + * + * @param __q the seed sequence. + */ + void + seed(seed_seq& __q); + + /** + * @brief Gets the smallest possible value in the output range. + * + * The minimum depends on the @p __c parameter: if it is zero, the + * minimum generated must be > 0, otherwise 0 is allowed. + * + * @todo This should be constexpr. + */ + result_type + min() const + { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; } + + /** + * @brief Gets the largest possible value in the output range. + * + * @todo This should be constexpr. + */ + result_type + max() const + { return __m - 1; } + + /** + * @brief Discard a sequence of random numbers. + * + * @todo Look for a faster way to do discard. + */ + void + discard(unsigned long long __z) + { + for (; __z != 0ULL; --__z) + (*this)(); + } + + /** + * @brief Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * @brief Compares two linear congruential random number generator + * objects of the same type for equality. + * + * @param __lhs A linear congruential random number generator object. + * @param __rhs Another linear congruential random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const linear_congruential_engine& __lhs, + const linear_congruential_engine& __rhs) + { return __lhs._M_x == __rhs._M_x; } + + /** + * @brief Writes the textual representation of the state x(i) of x to + * @p __os. + * + * @param __os The output stream. + * @param __lcr A % linear_congruential_engine random number generator. + * @returns __os. + */ + template<typename _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_engine<_UIntType1, __a1, __c1, + __m1>& __lcr); + + /** + * @brief Sets the state of the engine by reading its textual + * representation from @p __is. + * + * The textual representation must have been previously written using + * an output stream whose imbued locale and whose type's template + * specialization arguments _CharT and _Traits were the same as those + * of @p __is. + * + * @param __is The input stream. + * @param __lcr A % linear_congruential_engine random number generator. + * @returns __is. + */ + template<typename _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_engine<_UIntType1, + __a1, __c1, __m1>& __lcr); + + private: + template<typename _Gen> + void + seed(_Gen& __g, true_type) + { return seed(static_cast<unsigned long>(__g)); } + + template<typename _Gen> + void + seed(_Gen& __g, false_type); + + _UIntType _M_x; + }; + + + /** + * A generalized feedback shift register discrete random number generator. + * + * This algorithm avoids multiplication and division and is designed to be + * friendly to a pipelined architecture. If the parameters are chosen + * correctly, this generator will produce numbers with a very long period and + * fairly good apparent entropy, although still not cryptographically strong. + * + * The best way to use this generator is with the predefined mt19937 class. + * + * This algorithm was originally invented by Makoto Matsumoto and + * Takuji Nishimura. + * + * @var word_size The number of bits in each element of the state vector. + * @var state_size The degree of recursion. + * @var shift_size The period parameter. + * @var mask_bits The separation point bit index. + * @var parameter_a The last row of the twist matrix. + * @var output_u The first right-shift tempering matrix parameter. + * @var output_s The first left-shift tempering matrix parameter. + * @var output_b The first left-shift tempering matrix mask. + * @var output_t The second left-shift tempering matrix parameter. + * @var output_c The second left-shift tempering matrix mask. + * @var output_l The second right-shift tempering matrix parameter. + */ + template<typename _UIntType, size_t __w, + size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, + _UIntType __c, size_t __l, _UIntType __f> + class mersenne_twister_engine + { + __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) + + static_assert(__m >= 1U, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__n >= __m, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__w >= __r, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__w >= __u, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__w >= __s, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__w >= __t, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__w >= __l, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__w <= static_cast<size_t>(numeric_limits<_UIntType>::digits), + "mersenne_twister_engine template arguments out of bounds"); + +#if 0 + // XXX + static_assert(__a <= __detail::_ShiftMin1<_UIntType, __w>::__value, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__b <= __detail::_ShiftMin1<_UIntType, __w>::__value, + "mersenne_twister_engine template arguments out of bounds"); + static_assert(__c <= __detail::_ShiftMin1<_UIntType, __w>::__value, + "mersenne_twister_engine template arguments out of bounds"); +#endif + + public: + /** The type of the generated random value. */ + typedef _UIntType result_type; + + // parameter values + static const size_t word_size = __w; + static const size_t state_size = __n; + static const size_t shift_size = __m; + static const size_t mask_bits = __r; + static const result_type xor_mask = __a; + static const size_t tempering_u = __u; + static const result_type tempering_d = __d; + static const size_t tempering_s = __s; + static const result_type tempering_b = __b; + static const size_t tempering_t = __t; + static const result_type tempering_c = __c; + static const size_t tempering_l = __l; + static const size_t initialization_multiplier = __f; + static const result_type default_seed = 5489UL; + + // constructors and member function + explicit + mersenne_twister_engine(result_type __sd = default_seed) + { seed(__sd); } + + /** + * @brief Constructs a %mersenne_twister_engine random number generator + * engine seeded from the seed sequence @p __q. + * + * @param __q the seed sequence. + */ + explicit + mersenne_twister_engine(seed_seq& __q) + { seed(__q); } + + void + seed(result_type __sd = default_seed); + + void + seed(seed_seq& __q); + + /** + * @brief Gets the smallest possible value in the output range. + * + * @todo This should be constexpr. + */ + result_type + min() const + { return 0; }; + + /** + * @brief Gets the largest possible value in the output range. + * + * @todo This should be constexpr. + */ + result_type + max() const + { return __detail::_ShiftMin1<_UIntType, __w>::__value; } + + /** + * @brief Discard a sequence of random numbers. + * + * @todo Look for a faster way to do discard. + */ + void + discard(unsigned long long __z) + { + for (; __z != 0ULL; --__z) + (*this)(); + } + + result_type + operator()(); + + /** + * @brief Compares two % mersenne_twister_engine random number generator + * objects of the same type for equality. + * + * @param __lhs A % mersenne_twister_engine random number generator + * object. + * @param __rhs Another % mersenne_twister_engine random number + * generator object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const mersenne_twister_engine& __lhs, + const mersenne_twister_engine& __rhs) + { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); } + + /** + * @brief Inserts the current state of a % mersenne_twister_engine + * random number generator engine @p __x into the output stream + * @p __os. + * + * @param __os An output stream. + * @param __x A % mersenne_twister_engine random number generator + * engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _UIntType1, + size_t __w1, size_t __n1, + size_t __m1, size_t __r1, + _UIntType1 __a1, size_t __u1, + _UIntType1 __d1, size_t __s1, + _UIntType1 __b1, size_t __t1, + _UIntType1 __c1, size_t __l1, _UIntType1 __f1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1>& __x); + + /** + * @brief Extracts the current state of a % mersenne_twister_engine + * random number generator engine @p __x from the input stream + * @p __is. + * + * @param __is An input stream. + * @param __x A % mersenne_twister_engine random number generator + * engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template<typename _UIntType1, + size_t __w1, size_t __n1, + size_t __m1, size_t __r1, + _UIntType1 __a1, size_t __u1, + _UIntType1 __d1, size_t __s1, + _UIntType1 __b1, size_t __t1, + _UIntType1 __c1, size_t __l1, _UIntType1 __f1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __d1, __s1, __b1, __t1, __c1, __l1, __f1>& __x); + + private: + template<typename _Gen> + void + seed(_Gen& __g, true_type) + { return seed(static_cast<unsigned long>(__g)); } + + template<typename _Gen> + void + seed(_Gen& __g, false_type); + + _UIntType _M_x[state_size]; + size_t _M_p; + }; + + /** + * @brief The Marsaglia-Zaman generator. + * + * This is a model of a Generalized Fibonacci discrete random number + * generator, sometimes referred to as the SWC generator. + * + * A discrete random number generator that produces pseudorandom + * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} - + * carry_{i-1}) \bmod m @f$. + * + * The size of the state is @f$ r @f$ + * and the maximum period of the generator is @f$ m^r - m^s - 1 @f$. + * + * @var _M_x The state of the generator. This is a ring buffer. + * @var _M_carry The carry. + * @var _M_p Current index of x(i - r). + */ + template<typename _UIntType, size_t __w, size_t __s, size_t __r> + class subtract_with_carry_engine + { + __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) + static_assert(__s > 0U && __r > __s + && __w > 0U + && __w <= static_cast<size_t>(numeric_limits<_UIntType>::digits), + "template arguments out of bounds" + " in subtract_with_carry_engine"); + + public: + /** The type of the generated random value. */ + typedef _UIntType result_type; + + // parameter values + static const size_t word_size = __w; + static const size_t short_lag = __s; + static const size_t long_lag = __r; + static const result_type default_seed = 19780503; + + /** + * @brief Constructs an explicitly seeded % subtract_with_carry_engine + * random number generator. + */ + explicit + subtract_with_carry_engine(result_type __sd = default_seed) + { this->seed(__sd); } + + /** + * @brief Constructs a %subtract_with_carry_engine random number engine + * seeded from the seed sequence @p __q. + * + * @param __q the seed sequence. + */ + explicit + subtract_with_carry_engine(seed_seq& __q) + { this->seed(__q); } + + /** + * @brief Seeds the initial state @f$ x_0 @f$ of the random number + * generator. + * + * N1688[4.19] modifies this as follows. If @p __value == 0, + * sets value to 19780503. In any case, with a linear + * congruential generator lcg(i) having parameters @f$ m_{lcg} = + * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value + * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m + * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$ + * set carry to 1, otherwise sets carry to 0. + */ + void + seed(result_type __sd = default_seed); + + /** + * @brief Seeds the initial state @f$ x_0 @f$ of the + * % subtract_with_carry_engine random number generator. + */ + void + seed(seed_seq& __q); + + /** + * @brief Gets the inclusive minimum value of the range of random + * integers returned by this generator. + * + * @todo This should be constexpr. + */ + result_type + min() const + { return 0; } + + /** + * @brief Gets the inclusive maximum value of the range of random + * integers returned by this generator. + * + * @todo This should be constexpr. + */ + result_type + max() const + { return _S_modulus - 1U; } + + /** + * @brief Discard a sequence of random numbers. + * + * @todo Look for a faster way to do discard. + */ + void + discard(unsigned long long __z) + { + for (; __z != 0ULL; --__z) + (*this)(); + } + + /** + * @brief Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * @brief Compares two % subtract_with_carry_engine random number + * generator objects of the same type for equality. + * + * @param __lhs A % subtract_with_carry_engine random number generator + * object. + * @param __rhs Another % subtract_with_carry_engine random number + * generator object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const subtract_with_carry_engine& __lhs, + const subtract_with_carry_engine& __rhs) + { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); } + + /** + * @brief Inserts the current state of a % subtract_with_carry_engine + * random number generator engine @p __x into the output stream + * @p __os. + * + * @param __os An output stream. + * @param __x A % subtract_with_carry_engine random number generator + * engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UIntType1, __w1, __s1, + __r1>& __x); + + /** + * @brief Extracts the current state of a % subtract_with_carry_engine + * random number generator engine @p __x from the input stream + * @p __is. + * + * @param __is An input stream. + * @param __x A % subtract_with_carry_engine random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template<typename _UIntType1, size_t __w1, size_t __s1, size_t __r1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UIntType1, __w1, __s1, __r1>& __x); + + private: + template<typename _Gen> + void + seed(_Gen& __g, true_type) + { return seed(static_cast<unsigned long>(__g)); } + + template<typename _Gen> + void + seed(_Gen& __g, false_type); + + static const size_t _S_modulus + = __detail::_Shift<_UIntType, __w>::__value; + + _UIntType _M_x[long_lag]; + _UIntType _M_carry; + size_t _M_p; + }; + + /** + * Produces random numbers from some base engine by discarding blocks of + * data. + * + * 0 <= @p __r <= @p __p + */ + template<typename _RandomNumberEngine, size_t __p, size_t __r> + class discard_block_engine + { + static_assert(__r >= 1U && __p >= __r, + "template arguments out of bounds" + " in discard_block_engine"); + + public: + /** The type of the generated random value. */ + typedef typename _RandomNumberEngine::result_type result_type; + + // parameter values + static const size_t block_size = __p; + static const size_t used_block = __r; + + /** + * @brief Constructs a default %discard_block_engine engine. + * + * The underlying engine is default constructed as well. + */ + discard_block_engine() + : _M_b(), _M_n(0) { } + + /** + * @brief Copy constructs a %discard_block_engine engine. + * + * Copies an existing base class random number generator. + * @param rng An existing (base class) engine object. + */ + explicit + discard_block_engine(const _RandomNumberEngine& __rne) + : _M_b(__rne), _M_n(0) { } + + /** + * @brief Move constructs a %discard_block_engine engine. + * + * Copies an existing base class random number generator. + * @param rng An existing (base class) engine object. + */ + explicit + discard_block_engine(_RandomNumberEngine&& __rne) + : _M_b(std::move(__rne)), _M_n(0) { } + + /** + * @brief Seed constructs a %discard_block_engine engine. + * + * Constructs the underlying generator engine seeded with @p __s. + * @param __s A seed value for the base class engine. + */ + explicit + discard_block_engine(result_type __s) + : _M_b(__s), _M_n(0) { } + + /** + * @brief Generator construct a %discard_block_engine engine. + * + * @param __q A seed sequence. + */ + explicit + discard_block_engine(seed_seq& __q) + : _M_b(__q), _M_n(0) + { } + + /** + * @brief Reseeds the %discard_block_engine object with the default + * seed for the underlying base class generator engine. + */ + void + seed() + { + _M_b.seed(); + _M_n = 0; + } + + /** + * @brief Reseeds the %discard_block_engine object with the default + * seed for the underlying base class generator engine. + */ + void + seed(result_type __s) + { + _M_b.seed(__s); + _M_n = 0; + } + + /** + * @brief Reseeds the %discard_block_engine object with the given seed + * sequence. + * @param __q A seed generator function. + */ + void + seed(seed_seq& __q) + { + _M_b.seed(__q); + _M_n = 0; + } + + /** + * @brief Gets a const reference to the underlying generator engine + * object. + */ + const _RandomNumberEngine& + base() const + { return _M_b; } + + /** + * @brief Gets the minimum value in the generated random number range. + * + * @todo This should be constexpr. + */ + result_type + min() const + { return _M_b.min(); } + + /** + * @brief Gets the maximum value in the generated random number range. + * + * @todo This should be constexpr. + */ + result_type + max() const + { return _M_b.max(); } + + /** + * @brief Discard a sequence of random numbers. + * + * @todo Look for a faster way to do discard. + */ + void + discard(unsigned long long __z) + { + for (; __z != 0ULL; --__z) + (*this)(); + } + + /** + * @brief Gets the next value in the generated random number sequence. + */ + result_type + operator()(); + + /** + * @brief Compares two %discard_block_engine random number generator + * objects of the same type for equality. + * + * @param __lhs A %discard_block_engine random number generator object. + * @param __rhs Another %discard_block_engine random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const discard_block_engine& __lhs, + const discard_block_engine& __rhs) + { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); } + + /** + * @brief Inserts the current state of a %discard_block_engine random + * number generator engine @p __x into the output stream + * @p __os. + * + * @param __os An output stream. + * @param __x A %discard_block_engine random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RandomNumberEngine1, size_t __p1, size_t __r1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block_engine<_RandomNumberEngine1, + __p1, __r1>& __x); + + /** + * @brief Extracts the current state of a % subtract_with_carry_engine + * random number generator engine @p __x from the input stream + * @p __is. + * + * @param __is An input stream. + * @param __x A %discard_block_engine random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template<typename _RandomNumberEngine1, size_t __p1, size_t __r1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block_engine<_RandomNumberEngine1, + __p1, __r1>& __x); + + private: + _RandomNumberEngine _M_b; + size_t _M_n; + }; + + /** + * Produces random numbers by combining random numbers from some base + * engine to produce random numbers with a specifies number of bits @p __w. + */ + template<typename _RandomNumberEngine, size_t __w, typename _UIntType> + class independent_bits_engine + { + static_assert(__w > 0U + && __w <= static_cast<size_t>(numeric_limits<_UIntType>::digits), + "template arguments out of bounds" + " in independent_bits_engine"); + + public: + /** The type of the generated random value. */ + typedef _UIntType result_type; + + /** + * @brief Constructs a default %independent_bits_engine engine. + * + * The underlying engine is default constructed as well. + */ + independent_bits_engine() + : _M_b() { } + + /** + * @brief Copy constructs a %independent_bits_engine engine. + * + * Copies an existing base class random number generator. + * @param rng An existing (base class) engine object. + */ + explicit + independent_bits_engine(const _RandomNumberEngine& __rne) + : _M_b(__rne) { } + + /** + * @brief Move constructs a %independent_bits_engine engine. + * + * Copies an existing base class random number generator. + * @param rng An existing (base class) engine object. + */ + explicit + independent_bits_engine(_RandomNumberEngine&& __rne) + : _M_b(std::move(__rne)) { } + + /** + * @brief Seed constructs a %independent_bits_engine engine. + * + * Constructs the underlying generator engine seeded with @p __s. + * @param __s A seed value for the base class engine. + */ + explicit + independent_bits_engine(result_type __s) + : _M_b(__s) { } + + /** + * @brief Generator construct a %independent_bits_engine engine. + * + * @param __q A seed sequence. + */ + explicit + independent_bits_engine(seed_seq& __q) + : _M_b(__q) + { } + + /** + * @brief Reseeds the %independent_bits_engine object with the default + * seed for the underlying base class generator engine. + */ + void + seed() + { _M_b.seed(); } + + /** + * @brief Reseeds the %independent_bits_engine object with the default + * seed for the underlying base class generator engine. + */ + void + seed(result_type __s) + { _M_b.seed(__s); } + + /** + * @brief Reseeds the %independent_bits_engine object with the given + * seed sequence. + * @param __q A seed generator function. + */ + void + seed(seed_seq& __q) + { _M_b.seed(__q); } + + /** + * @brief Gets a const reference to the underlying generator engine + * object. + */ + const _RandomNumberEngine& + base() const + { return _M_b; } + + /** + * @brief Gets the minimum value in the generated random number range. + * + * @todo This should be constexpr. + */ + result_type + min() const + { return 0U; } + + /** + * @brief Gets the maximum value in the generated random number range. + * + * @todo This should be constexpr. + */ + result_type + max() const + { return __detail::_ShiftMin1<_UIntType, __w>::__value; } + + /** + * @brief Discard a sequence of random numbers. + * + * @todo Look for a faster way to do discard. + */ + void + discard(unsigned long long __z) + { + for (; __z != 0ULL; --__z) + (*this)(); + } + + /** + * @brief Gets the next value in the generated random number sequence. + */ + result_type + operator()(); + + /** + * @brief Compares two %independent_bits_engine random number generator + * objects of the same type for equality. + * + * @param __lhs A %independent_bits_engine random number generator + * object. + * @param __rhs Another %independent_bits_engine random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const independent_bits_engine& __lhs, + const independent_bits_engine& __rhs) + { return __lhs._M_b == __rhs._M_b; } + + /** + * @brief Extracts the current state of a % subtract_with_carry_engine + * random number generator engine @p __x from the input stream + * @p __is. + * + * @param __is An input stream. + * @param __x A %independent_bits_engine random number generator + * engine. + * + * @returns The input stream with the state of @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, + independent_bits_engine<_RandomNumberEngine, + __w, _UIntType>& __x) + { + __is >> __x._M_b; + return __is; + } + + private: + _RandomNumberEngine _M_b; + }; + + /** + * @brief Inserts the current state of a %independent_bits_engine random + * number generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %independent_bits_engine random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RandomNumberEngine, size_t __w, typename _UIntType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const independent_bits_engine<_RandomNumberEngine, + __w, _UIntType>& __x) + { + __os << __x.base(); + return __os; + } + + /** + * @brief Produces random numbers by combining random numbers from some + * base engine to produce random numbers with a specifies number of bits + * @p __w. + */ + template<typename _RandomNumberEngine, size_t __k> + class shuffle_order_engine + { + static_assert(__k >= 1U, + "template arguments out of bounds" + " in shuffle_order_engine"); + + public: + /** The type of the generated random value. */ + typedef typename _RandomNumberEngine::result_type result_type; + + static const size_t table_size = __k; + + /** + * @brief Constructs a default %shuffle_order_engine engine. + * + * The underlying engine is default constructed as well. + */ + shuffle_order_engine() + : _M_b() + { _M_initialize(); } + + /** + * @brief Copy constructs a %shuffle_order_engine engine. + * + * Copies an existing base class random number generator. + * @param rng An existing (base class) engine object. + */ + explicit + shuffle_order_engine(const _RandomNumberEngine& __rne) + : _M_b(__rne) + { _M_initialize(); } + + /** + * @brief Move constructs a %shuffle_order_engine engine. + * + * Copies an existing base class random number generator. + * @param rng An existing (base class) engine object. + */ + explicit + shuffle_order_engine(_RandomNumberEngine&& __rne) + : _M_b(std::move(__rne)) + { _M_initialize(); } + + /** + * @brief Seed constructs a %shuffle_order_engine engine. + * + * Constructs the underlying generator engine seeded with @p __s. + * @param __s A seed value for the base class engine. + */ + explicit + shuffle_order_engine(result_type __s) + : _M_b(__s) + { _M_initialize(); } + + /** + * @brief Generator construct a %shuffle_order_engine engine. + * + * @param __q A seed sequence. + */ + explicit + shuffle_order_engine(seed_seq& __q) + : _M_b(__q) + { _M_initialize(); } + + /** + * @brief Reseeds the %shuffle_order_engine object with the default seed for + * the underlying base class generator engine. + */ + void + seed() + { + _M_b.seed(); + _M_initialize(); + } + + /** + * @brief Reseeds the %shuffle_order_engine object with the default seed + * for the underlying base class generator engine. + */ + void + seed(result_type __s) + { + _M_b.seed(__s); + _M_initialize(); + } + + /** + * @brief Reseeds the %shuffle_order_engine object with the given seed + * sequence. + * @param __q A seed generator function. + */ + void + seed(seed_seq& __q) + { + _M_b.seed(__q); + _M_initialize(); + } + + /** + * Gets a const reference to the underlying generator engine object. + */ + const _RandomNumberEngine& + base() const + { return _M_b; } + + /** + * Gets the minimum value in the generated random number range. + * + * @todo This should be constexpr. + */ + result_type + min() const + { return _M_b.min(); } + + /** + * Gets the maximum value in the generated random number range. + * + * @todo This should be constexpr. + */ + result_type + max() const + { return _M_b.max(); } + + /** + * Discard a sequence of random numbers. + * + * @todo Look for a faster way to do discard. + */ + void + discard(unsigned long long __z) + { + for (; __z != 0ULL; --__z) + (*this)(); + } + + /** + * Gets the next value in the generated random number sequence. + */ + result_type + operator()(); + + /** + * Compares two %shuffle_order_engine random number generator objects + * of the same type for equality. + * + * @param __lhs A %shuffle_order_engine random number generator object. + * @param __rhs Another %shuffle_order_engine random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const shuffle_order_engine& __lhs, + const shuffle_order_engine& __rhs) + { return __lhs._M_b == __rhs._M_b; } + + /** + * @brief Inserts the current state of a %shuffle_order_engine random + * number generator engine @p __x into the output stream + @p __os. + * + * @param __os An output stream. + * @param __x A %shuffle_order_engine random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RandomNumberEngine1, size_t __k1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const shuffle_order_engine<_RandomNumberEngine1, + __k1>& __x); + + /** + * @brief Extracts the current state of a % subtract_with_carry_engine + * random number generator engine @p __x from the input stream + * @p __is. + * + * @param __is An input stream. + * @param __x A %shuffle_order_engine random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template<typename _RandomNumberEngine1, size_t __k1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + shuffle_order_engine<_RandomNumberEngine1, + __k1>& __x); + + private: + void _M_initialize() + { + for (size_t __i = 0; __i < __k; ++__i) + _M_v[__i] = _M_b(); + _M_y = _M_b(); + } + + _RandomNumberEngine _M_b; + result_type _M_v[__k]; + result_type _M_y; + }; + + /** + * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller. + */ + typedef linear_congruential_engine<uint_fast32_t, 16807UL, 0UL, 2147483647UL> + minstd_rand0; + + /** + * An alternative LCR (Lehmer Generator function) . + */ + typedef linear_congruential_engine<uint_fast32_t, 48271UL, 0UL, 2147483647UL> + minstd_rand; + + /** + * The classic Mersenne Twister. + * + * Reference: + * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally + * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions + * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. + */ + typedef mersenne_twister_engine< + uint_fast32_t, + 32, 624, 397, 31, + 0x9908b0dfUL, 11, + 0xffffffffUL, 7, + 0x9d2c5680UL, 15, + 0xefc60000UL, 18, 1812433253UL> mt19937; + + /** + * An alternative Mersenne Twister. + */ + typedef mersenne_twister_engine< + uint_fast64_t, + 64, 312, 156, 31, + 0xb5026f5aa96619e9ULL, 29, + 0x5555555555555555ULL, 17, + 0x71d67fffeda60000ULL, 37, + 0xfff7eee000000000ULL, 43, + 6364136223846793005ULL> mt19937_64; + + /** + * . + */ + typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> + ranlux24_base; + + typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; + + typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> + ranlux48_base; + + typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; + + /** + * . + */ + typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; + + /** + * . + */ + typedef minstd_rand0 default_random_engine; + + /** + * A standard interface to a platform-specific non-deterministic + * random number generator (if any are available). + */ + class random_device + { + public: + /** The type of the generated random value. */ + typedef unsigned int result_type; + + // constructors, destructors and member functions + +#ifdef _GLIBCXX_USE_RANDOM_TR1 + + explicit + random_device(const std::string& __token = "/dev/urandom") + { + if ((__token != "/dev/urandom" && __token != "/dev/random") + || !(_M_file = std::fopen(__token.c_str(), "rb"))) + std::__throw_runtime_error(__N("random_device::" + "random_device(const std::string&)")); + } + + ~random_device() + { std::fclose(_M_file); } + +#else + + explicit + random_device(const std::string& __token = "mt19937") + : _M_mt(_M_strtoul(__token)) { } + + private: + static unsigned long + _M_strtoul(const std::string& __str) + { + unsigned long __ret = 5489UL; + if (__str != "mt19937") + { + const char* __nptr = __str.c_str(); + char* __endptr; + __ret = std::strtoul(__nptr, &__endptr, 0); + if (*__nptr == '\0' || *__endptr != '\0') + std::__throw_runtime_error(__N("random_device::_M_strtoul" + "(const std::string&)")); + } + return __ret; + } + + public: + +#endif + + result_type + min() const + { return std::numeric_limits<result_type>::min(); } + + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + double + entropy() const + { return 0.0; } + + result_type + operator()() + { +#ifdef _GLIBCXX_USE_RANDOM_TR1 + result_type __ret; + std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type), + 1, _M_file); + return __ret; +#else + return _M_mt(); +#endif + } + + // No copy functions. + random_device(const random_device&) = delete; + void operator=(const random_device&) = delete; + + private: + +#ifdef _GLIBCXX_USE_RANDOM_TR1 + FILE* _M_file; +#else + mt19937 _M_mt; +#endif + }; + + /* @} */ // group std_random_generators + + /** + * @addtogroup std_random_distributions Random Number Distributions + * @ingroup std_random + * @{ + */ + + /** + * @addtogroup std_random_distributions_uniform Uniform Distributions + * @ingroup std_random_distributions + * @{ + */ + + /** + * @brief Uniform discrete distribution for random numbers. + * A discrete random distribution on the range @f$[min, max]@f$ with equal + * probability throughout the range. + */ + template<typename _IntType = int> + class uniform_int_distribution + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the range of the distribution. */ + typedef _IntType result_type; + /** Parameter type. */ + struct param_type + { + typedef uniform_int_distribution<_IntType> distribution_type; + + explicit + param_type(_IntType __a = 0, _IntType __b = 9) + : _M_a(__a), _M_b(__b) + { + _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b); + } + + result_type + a() const + { return _M_a; } + + result_type + b() const + { return _M_b; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); } + + private: + _IntType _M_a; + _IntType _M_b; + }; + + public: + /** + * @brief Constructs a uniform distribution object. + */ + explicit + uniform_int_distribution(_IntType __a = 0, _IntType __b = 9) + : _M_param(__a, __b) + { } + + explicit + uniform_int_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + * + * Does nothing for the uniform integer distribution. + */ + void + reset() { } + + result_type + a() const + { return _M_param.a(); } + + result_type + b() const + { return _M_param.b(); } + + /** + * @brief Returns the inclusive lower bound of the distribution range. + */ + result_type + min() const + { return this->a(); } + + /** + * @brief Returns the inclusive upper bound of the distribution range. + */ + result_type + max() const + { return this->b(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * Gets a uniformly distributed random number in the range + * @f$(min, max)@f$. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + typedef typename _UniformRandomNumberGenerator::result_type + _UResult_type; + return _M_call(__urng, this->a(), this->b(), + typename is_integral<_UResult_type>::type()); + } + + /** + * Gets a uniform random number in the range @f$[0, n)@f$. + * + * This function is aimed at use with std::random_shuffle. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + typedef typename _UniformRandomNumberGenerator::result_type + _UResult_type; + return _M_call(__urng, __p.a(), __p.b(), + typename is_integral<_UResult_type>::type()); + } + + private: + template<typename _UniformRandomNumberGenerator> + result_type + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, true_type); + + template<typename _UniformRandomNumberGenerator> + result_type + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, false_type) + { + return result_type((__urng() - __urng.min()) + / (__urng.max() - __urng.min()) + * (__max - __min + 1)) + __min; + } + + param_type _M_param; + }; + + /** + * @brief Return true if two uniform integer distributions have + * the same parameters. + */ + template<typename _IntType> + bool + operator==(const uniform_int_distribution<_IntType>& __d1, + const uniform_int_distribution<_IntType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %uniform_int_distribution random number + * distribution @p __x into the output stream @p os. + * + * @param __os An output stream. + * @param __x A %uniform_int_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int_distribution<_IntType>& __x); + + /** + * @brief Extracts a %uniform_int_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %uniform_int_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int_distribution<_IntType>& __x); + + + /** + * @brief Uniform continuous distribution for random numbers. + * + * A continuous random distribution on the range [min, max) with equal + * probability throughout the range. The URNG should be real-valued and + * deliver number in the range [0, 1). + */ + template<typename _RealType = double> + class uniform_real_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef uniform_real_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __a = _RealType(0), + _RealType __b = _RealType(1)) + : _M_a(__a), _M_b(__b) + { + _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b); + } + + result_type + a() const + { return _M_a; } + + result_type + b() const + { return _M_b; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); } + + private: + _RealType _M_a; + _RealType _M_b; + }; + + public: + /** + * @brief Constructs a uniform_real_distribution object. + * + * @param __min [IN] The lower bound of the distribution. + * @param __max [IN] The upper bound of the distribution. + */ + explicit + uniform_real_distribution(_RealType __a = _RealType(0), + _RealType __b = _RealType(1)) + : _M_param(__a, __b) + { } + + explicit + uniform_real_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + * + * Does nothing for the uniform real distribution. + */ + void + reset() { } + + result_type + a() const + { return _M_param.a(); } + + result_type + b() const + { return _M_param.b(); } + + /** + * @brief Returns the inclusive lower bound of the distribution range. + */ + result_type + min() const + { return this->a(); } + + /** + * @brief Returns the inclusive upper bound of the distribution range. + */ + result_type + max() const + { return this->b(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + return (__aurng() * (this->b() - this->a())) + this->a(); + } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + return (__aurng() * (__p.b() - __p.a())) + __p.a(); + } + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two uniform real distributions have + * the same parameters. + */ + template<typename _IntType> + bool + operator==(const uniform_real_distribution<_IntType>& __d1, + const uniform_real_distribution<_IntType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %uniform_real_distribution random number + * distribution @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %uniform_real_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real_distribution<_RealType>& __x); + + /** + * @brief Extracts a %uniform_real_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %uniform_real_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real_distribution<_RealType>& __x); + + /* @} */ // group std_random_distributions_uniform + + /** + * @addtogroup std_random_distributions_normal Normal Distributions + * @ingroup std_random_distributions + * @{ + */ + + /** + * @brief A normal continuous distribution for random numbers. + * + * The formula for the normal probability density function is + * @f$ p(x|\mu,\sigma) = \frac{1}{\sigma \sqrt{2 \pi}} + * e^{- \frac{{x - \mu}^ {2}}{2 \sigma ^ {2}} } @f$. + */ + template<typename _RealType = double> + class normal_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef normal_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __mean = _RealType(0), + _RealType __stddev = _RealType(1)) + : _M_mean(__mean), _M_stddev(__stddev) + { + _GLIBCXX_DEBUG_ASSERT(_M_stddev > _RealType(0)); + } + + _RealType + mean() const + { return _M_mean; } + + _RealType + stddev() const + { return _M_stddev; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_mean == __p2._M_mean) + && (__p1._M_stddev == __p2._M_stddev); } + + private: + _RealType _M_mean; + _RealType _M_stddev; + }; + + public: + /** + * Constructs a normal distribution with parameters @f$ mean @f$ and + * standard deviation. + */ + explicit + normal_distribution(result_type __mean = result_type(0), + result_type __stddev = result_type(1)) + : _M_param(__mean, __stddev), _M_saved_available(false) + { } + + explicit + normal_distribution(const param_type& __p) + : _M_param(__p), _M_saved_available(false) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { _M_saved_available = false; } + + /** + * @brief Returns the mean of the distribution. + */ + _RealType + mean() const + { return _M_param.mean(); } + + /** + * @brief Returns the standard deviation of the distribution. + */ + _RealType + stddev() const + { return _M_param.stddev(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return std::numeric_limits<result_type>::min(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + /** + * @brief Return true if two normal distributions have + * the same parameters. + */ + template<typename _RealType1> + friend bool + operator==(const normal_distribution<_RealType1>& __d1, + const normal_distribution<_RealType1>& __d2); + + /** + * @brief Inserts a %normal_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %normal_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType1>& __x); + + /** + * @brief Extracts a %normal_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %normal_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType1>& __x); + + private: + param_type _M_param; + result_type _M_saved; + bool _M_saved_available; + }; + + + /** + * @brief A lognormal_distribution random number distribution. + * + * The formula for the normal probability mass function is + * @f$ p(x|m,s) = \frac{1}{sx\sqrt{2\pi}} + * \exp{-\frac{(\ln{x} - m)^2}{2s^2}} @f$ + */ + template<typename _RealType = double> + class lognormal_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef lognormal_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __m = _RealType(0), + _RealType __s = _RealType(1)) + : _M_m(__m), _M_s(__s) + { } + + _RealType + m() const + { return _M_m; } + + _RealType + s() const + { return _M_s; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_m == __p2._M_m) && (__p1._M_s == __p2._M_s); } + + private: + _RealType _M_m; + _RealType _M_s; + }; + + explicit + lognormal_distribution(_RealType __m = _RealType(0), + _RealType __s = _RealType(1)) + : _M_param(__m, __s) + { } + + explicit + lognormal_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * Resets the distribution state. + */ + void + reset() + { } + + /** + * + */ + _RealType + m() const + { return _M_param.m(); } + + _RealType + s() const + { return _M_param.s(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two lognormal distributions have + * the same parameters. + */ + template<typename _RealType> + bool + operator==(const lognormal_distribution<_RealType>& __d1, + const lognormal_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %lognormal_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %lognormal_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RealType>& __x); + + /** + * @brief Extracts a %lognormal_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %lognormal_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RealType>& __x); + + + /** + * @brief A chi_squared_distribution random number distribution. + * + * The formula for the normal probability mass function is + * @f$ p(x|n) = \frac{x^{(n/2) - 1}e^{-x/2}}{\Gamma(n/2) 2^{n/2}} @f$ + */ + template<typename _RealType = double> + class chi_squared_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef chi_squared_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __n = _RealType(1)) + : _M_n(__n) + { } + + _RealType + n() const + { return _M_n; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_n == __p2._M_n; } + + private: + _RealType _M_n; + }; + + explicit + chi_squared_distribution(_RealType __n = _RealType(1)) + : _M_param(__n) + { } + + explicit + chi_squared_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * + */ + _RealType + n() const + { return _M_param.n(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two Chi-squared distributions have + * the same parameters. + */ + template<typename _RealType> + bool + operator==(const chi_squared_distribution<_RealType>& __d1, + const chi_squared_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %chi_squared_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %chi_squared_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const chi_squared_distribution<_RealType>& __x); + + /** + * @brief Extracts a %chi_squared_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %chi_squared_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + chi_squared_distribution<_RealType>& __x); + + + /** + * @brief A cauchy_distribution random number distribution. + * + * The formula for the normal probability mass function is + * @f$ p(x|a,b) = \( \pi b \( 1 + \( \frac{x-a}{b} \)^2 \) \)^{-1} @f$ + */ + template<typename _RealType = double> + class cauchy_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef cauchy_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __a = _RealType(0), + _RealType __b = _RealType(1)) + : _M_a(__a), _M_b(__b) + { } + + _RealType + a() const + { return _M_a; } + + _RealType + b() const + { return _M_b; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); } + + private: + _RealType _M_a; + _RealType _M_b; + }; + + explicit + cauchy_distribution(_RealType __a = _RealType(0), + _RealType __b = _RealType(1)) + : _M_param(__a, __b) + { } + + explicit + cauchy_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * + */ + _RealType + a() const + { return _M_param.a(); } + + _RealType + b() const + { return _M_param.b(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return std::numeric_limits<result_type>::min(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two Cauchy distributions have + * the same parameters. + */ + template<typename _RealType> + bool + operator==(const cauchy_distribution<_RealType>& __d1, + const cauchy_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %cauchy_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %cauchy_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const cauchy_distribution<_RealType>& __x); + + /** + * @brief Extracts a %cauchy_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %cauchy_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + cauchy_distribution<_RealType>& __x); + + + /** + * @brief A fisher_f_distribution random number distribution. + * + * The formula for the normal probability mass function is + * @f$ p(x|m,n) = \frac{\Gamma((m+n)/2)}{\Gamma(m/2)\Gamma(n/2)} + * \(\frac{m}{n}\)^{m/2} x^{(m/2)-1} + * \( 1 + \frac{mx}{n} \)^{-(m+n)/2} @f$ + */ + template<typename _RealType = double> + class fisher_f_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef fisher_f_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __m = _RealType(1), + _RealType __n = _RealType(1)) + : _M_m(__m), _M_n(__n) + { } + + _RealType + m() const + { return _M_m; } + + _RealType + n() const + { return _M_n; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_m == __p2._M_m) && (__p1._M_n == __p2._M_n); } + + private: + _RealType _M_m; + _RealType _M_n; + }; + + explicit + fisher_f_distribution(_RealType __m = _RealType(1), + _RealType __n = _RealType(1)) + : _M_param(__m, __n) + { } + + explicit + fisher_f_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * + */ + _RealType + m() const + { return _M_param.m(); } + + _RealType + n() const + { return _M_param.n(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two Fisher f distributions have + * the same parameters. + */ + template<typename _RealType> + bool + operator==(const fisher_f_distribution<_RealType>& __d1, + const fisher_f_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %fisher_f_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %fisher_f_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const fisher_f_distribution<_RealType>& __x); + + /** + * @brief Extracts a %fisher_f_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %fisher_f_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + fisher_f_distribution<_RealType>& __x); + + + /** + * @brief A student_t_distribution random number distribution. + * + * The formula for the normal probability mass function is + * @f$ p(x|n) = \frac{1}{\sqrt(n\pi)} \frac{\Gamma((n+1)/2)}{\Gamma(n/2)} + * \( 1 + \frac{x^2}{n} \) ^{-(n+1)/2} @f$ + */ + template<typename _RealType = double> + class student_t_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef student_t_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __n = _RealType(1)) + : _M_n(__n) + { } + + _RealType + n() const + { return _M_n; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_n == __p2._M_n; } + + private: + _RealType _M_n; + }; + + explicit + student_t_distribution(_RealType __n = _RealType(1)) + : _M_param(__n) + { } + + explicit + student_t_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * + */ + _RealType + n() const + { return _M_param.n(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return std::numeric_limits<result_type>::min(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + template<typename _UniformRandomNumberGenerator> + result_type + _M_gaussian(_UniformRandomNumberGenerator& __urng, + const result_type __sigma); + + param_type _M_param; + }; + + /** + * @brief Return true if two Student t distributions have + * the same parameters. + */ + template<typename _RealType> + bool + operator==(const student_t_distribution<_RealType>& __d1, + const student_t_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %student_t_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %student_t_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const student_t_distribution<_RealType>& __x); + + /** + * @brief Extracts a %student_t_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %student_t_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + student_t_distribution<_RealType>& __x); + + /* @} */ // group std_random_distributions_normal + + /** + * @addtogroup std_random_distributions_bernoulli Bernoulli Distributions + * @ingroup std_random_distributions + * @{ + */ + + /** + * @brief A Bernoulli random number distribution. + * + * 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 + { + public: + /** The type of the range of the distribution. */ + typedef bool result_type; + /** Parameter type. */ + struct param_type + { + typedef bernoulli_distribution distribution_type; + + explicit + param_type(double __p = 0.5) + : _M_p(__p) + { + _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0)); + } + + double + p() const + { return _M_p; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_p == __p2._M_p; } + + private: + double _M_p; + }; + + public: + /** + * @brief Constructs a Bernoulli distribution with likelihood @p p. + * + * @param __p [IN] The likelihood of a true result being returned. + * Must be in the interval @f$ [0, 1] @f$. + */ + explicit + bernoulli_distribution(double __p = 0.5) + : _M_param(__p) + { } + + explicit + bernoulli_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + * + * Does nothing for a Bernoulli distribution. + */ + void + reset() { } + + /** + * @brief Returns the @p p parameter of the distribution. + */ + double + p() const + { return _M_param.p(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return std::numeric_limits<result_type>::min(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + /** + * @brief Returns the next value in the Bernoullian sequence. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, double> + __aurng(__urng); + if ((__aurng() - __aurng.min()) + < this->p() * (__aurng.max() - __aurng.min())) + return true; + return false; + } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, double> + __aurng(__urng); + if ((__aurng() - __aurng.min()) + < __p.p() * (__aurng.max() - __aurng.min())) + return true; + return false; + } + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two Bernoulli distributions have + * the same parameters. + */ + bool + operator==(const bernoulli_distribution& __d1, + const bernoulli_distribution& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %bernoulli_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %bernoulli_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x); + + /** + * @brief Extracts a %bernoulli_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %bernoulli_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + bernoulli_distribution& __x) + { + double __p; + __is >> __p; + __x.param(bernoulli_distribution::param_type(__p)); + return __is; + } + + + /** + * @brief A discrete binomial random number distribution. + * + * The formula for the binomial probability density function is + * @f$ p(i|t,p) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$ + * and @f$ p @f$ are the parameters of the distribution. + */ + template<typename _IntType = int> + class binomial_distribution + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the range of the distribution. */ + typedef _IntType result_type; + /** Parameter type. */ + struct param_type + { + typedef binomial_distribution<_IntType> distribution_type; + friend class binomial_distribution<_IntType>; + + explicit + param_type(_IntType __t = _IntType(1), double __p = 0.5) + : _M_t(__t), _M_p(__p) + { + _GLIBCXX_DEBUG_ASSERT((_M_t >= _IntType(0)) + && (_M_p >= 0.0) + && (_M_p <= 1.0)); + _M_initialize(); + } + + _IntType + t() const + { return _M_t; } + + double + p() const + { return _M_p; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_t == __p2._M_t) && (__p1._M_p == __p2._M_p); } + + private: + void + _M_initialize(); + + _IntType _M_t; + double _M_p; + + double _M_q; +#if _GLIBCXX_USE_C99_MATH_TR1 + double _M_d1, _M_d2, _M_s1, _M_s2, _M_c, + _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p; +#endif + bool _M_easy; + }; + + // constructors and member function + explicit + binomial_distribution(_IntType __t = _IntType(1), + double __p = 0.5) + : _M_param(__t, __p), _M_nd() + { } + + explicit + binomial_distribution(const param_type& __p) + : _M_param(__p), _M_nd() + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { _M_nd.reset(); } + + /** + * @brief Returns the distribution @p t parameter. + */ + _IntType + t() const + { return _M_param.t(); } + + /** + * @brief Returns the distribution @p p parameter. + */ + double + p() const + { return _M_param.p(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return 0; } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return _M_param.t(); } + + /** + * @brief Return true if two binomial distributions have + * the same parameters. + */ + template<typename _IntType1> + friend bool + operator==(const binomial_distribution<_IntType1>& __d1, + const binomial_distribution<_IntType1>& __d2) + { return (__d1.param() == __d2.param()) + && (__d1._M_nd == __d2._M_nd); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + /** + * @brief Inserts a %binomial_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %binomial_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType1>& __x); + + /** + * @brief Extracts a %binomial_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %binomial_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<typename _IntType1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType1>& __x); + + private: + template<typename _UniformRandomNumberGenerator> + result_type + _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t); + + param_type _M_param; + + // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. + normal_distribution<double> _M_nd; + }; + + + /** + * @brief A discrete geometric random number distribution. + * + * The formula for the geometric probability density function is + * @f$ p(i|p) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the + * distribution. + */ + template<typename _IntType = int> + class geometric_distribution + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the range of the distribution. */ + typedef _IntType result_type; + /** Parameter type. */ + struct param_type + { + typedef geometric_distribution<_IntType> distribution_type; + friend class geometric_distribution<_IntType>; + + explicit + param_type(double __p = 0.5) + : _M_p(__p) + { + _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) + && (_M_p <= 1.0)); + _M_initialize(); + } + + double + p() const + { return _M_p; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_p == __p2._M_p; } + + private: + void + _M_initialize() + { _M_log_p = std::log(_M_p); } + + double _M_p; + + double _M_log_p; + }; + + // constructors and member function + explicit + geometric_distribution(double __p = 0.5) + : _M_param(__p) + { } + + explicit + geometric_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + * + * Does nothing for the geometric distribution. + */ + void + reset() { } + + /** + * @brief Returns the distribution parameter @p p. + */ + double + p() const + { return _M_param.p(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return 0; } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two geometric distributions have + * the same parameters. + */ + template<typename _IntType> + bool + operator==(const geometric_distribution<_IntType>& __d1, + const geometric_distribution<_IntType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %geometric_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %geometric_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType>& __x); + + /** + * @brief Extracts a %geometric_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %geometric_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + geometric_distribution<_IntType>& __x); + + + /** + * @brief A negative_binomial_distribution random number distribution. + * + * The formula for the negative binomial probability mass function is + * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$ + * and @f$ p @f$ are the parameters of the distribution. + */ + template<typename _IntType = int> + class negative_binomial_distribution + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the range of the distribution. */ + typedef _IntType result_type; + /** Parameter type. */ + struct param_type + { + typedef negative_binomial_distribution<_IntType> distribution_type; + + explicit + param_type(_IntType __k = 1, double __p = 0.5) + : _M_k(__k), _M_p(__p) + { } + + _IntType + k() const + { return _M_k; } + + double + p() const + { return _M_p; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_k == __p2._M_k) && (__p1._M_p == __p2._M_p); } + + private: + _IntType _M_k; + double _M_p; + }; + + explicit + negative_binomial_distribution(_IntType __k = 1, double __p = 0.5) + : _M_param(__k, __p) + { } + + explicit + negative_binomial_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Return the @f$ k @f$ parameter of the distribution. + */ + _IntType + k() const + { return _M_param.k(); } + + /** + * @brief Return the @f$ p @f$ parameter of the distribution. + */ + double + p() const + { return _M_param.p(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two negative binomial distributions have + * the same parameters. + */ + template<typename _IntType> + bool + operator==(const negative_binomial_distribution<_IntType>& __d1, + const negative_binomial_distribution<_IntType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %negative_binomial_distribution random + * number distribution @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %negative_binomial_distribution random number + * distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const negative_binomial_distribution<_IntType>& __x); + + /** + * @brief Extracts a %negative_binomial_distribution random number + * distribution @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %negative_binomial_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + negative_binomial_distribution<_IntType>& __x); + + /* @} */ // group std_random_distributions_bernoulli + + /** + * @addtogroup std_random_distributions_poisson Poisson Distributions + * @ingroup std_random_distributions + * @{ + */ + + /** + * @brief A discrete Poisson random number distribution. + * + * The formula for the Poisson probability density function is + * @f$ p(i|\mu) = \frac{\mu^i}{i!} e^{-\mu} @f$ where @f$ \mu @f$ is the + * parameter of the distribution. + */ + template<typename _IntType = int> + class poisson_distribution + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the range of the distribution. */ + typedef _IntType result_type; + /** Parameter type. */ + struct param_type + { + typedef poisson_distribution<_IntType> distribution_type; + friend class poisson_distribution<_IntType>; + + explicit + param_type(double __mean = 1.0) + : _M_mean(__mean) + { + _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0); + _M_initialize(); + } + + double + mean() const + { return _M_mean; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_mean == __p2._M_mean; } + + private: + // Hosts either log(mean) or the threshold of the simple method. + void + _M_initialize(); + + double _M_mean; + + double _M_lm_thr; +#if _GLIBCXX_USE_C99_MATH_TR1 + double _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb; +#endif + }; + + // constructors and member function + explicit + poisson_distribution(double __mean = 1.0) + : _M_param(__mean), _M_nd() + { } + + explicit + poisson_distribution(const param_type& __p) + : _M_param(__p), _M_nd() + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { _M_nd.reset(); } + + /** + * @brief Returns the distribution parameter @p mean. + */ + double + mean() const + { return _M_param.mean(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return 0; } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + /** + * @brief Return true if two Poisson distributions have the same + * parameters. + */ + template<typename _IntType1> + friend bool + operator==(const poisson_distribution<_IntType1>& __d1, + const poisson_distribution<_IntType1>& __d2) + { return (__d1.param() == __d2.param()) + && (__d1._M_nd == __d2._M_nd); } + + /** + * @brief Inserts a %poisson_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %poisson_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType1>& __x); + + /** + * @brief Extracts a %poisson_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %poisson_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<typename _IntType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType1>& __x); + + private: + param_type _M_param; + + // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. + normal_distribution<double> _M_nd; + }; + + /** + * @brief An exponential continuous distribution for random numbers. + * + * The formula for the exponential probability density function is + * @f$ p(x|\lambda) = \lambda e^{-\lambda x} @f$. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr> + * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr> + * <tr><td>Mode</td><td>@f$ zero @f$</td></tr> + * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr> + * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr> + * </table> + */ + template<typename _RealType = double> + class exponential_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef exponential_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __lambda = _RealType(1)) + : _M_lambda(__lambda) + { + _GLIBCXX_DEBUG_ASSERT(_M_lambda > _RealType(0)); + } + + _RealType + lambda() const + { return _M_lambda; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_lambda == __p2._M_lambda; } + + private: + _RealType _M_lambda; + }; + + public: + /** + * @brief Constructs an exponential distribution with inverse scale + * parameter @f$ \lambda @f$. + */ + explicit + exponential_distribution(const result_type& __lambda = result_type(1)) + : _M_param(__lambda) + { } + + explicit + exponential_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + * + * Has no effect on exponential distributions. + */ + void + reset() { } + + /** + * @brief Returns the inverse scale parameter of the distribution. + */ + _RealType + lambda() const + { return _M_param.lambda(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + return -std::log(__aurng()) / this->lambda(); + } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + return -std::log(__aurng()) / __p.lambda(); + } + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two exponential distributions have the same + * parameters. + */ + template<typename _RealType> + bool + operator==(const exponential_distribution<_RealType>& __d1, + const exponential_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %exponential_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %exponential_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x); + + /** + * @brief Extracts a %exponential_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %exponential_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + exponential_distribution<_RealType>& __x); + + + /** + * @brief A gamma continuous distribution for random numbers. + * + * The formula for the gamma probability density function is + * @f$ p(x|\alpha,\beta) = \frac{1}{\beta\Gamma(\alpha)} + * (x/\beta)^{\alpha - 1} e^{-x/\beta} @f$. + */ + template<typename _RealType = double> + class gamma_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef gamma_distribution<_RealType> distribution_type; + friend class gamma_distribution<_RealType>; + + explicit + param_type(_RealType __alpha = _RealType(1), + _RealType __beta = _RealType(1)) + : _M_alpha(__alpha), _M_beta(__beta) + { + _GLIBCXX_DEBUG_ASSERT(_M_alpha > _RealType(0)); + _M_initialize(); + } + + _RealType + alpha() const + { return _M_alpha; } + + _RealType + beta() const + { return _M_beta; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_alpha == __p2._M_alpha) + && (__p1._M_beta == __p2._M_beta); } + + private: + void + _M_initialize(); + + _RealType _M_alpha; + _RealType _M_beta; + + // Hosts either lambda of GB or d of modified Vaduva's. + _RealType _M_l_d; + }; + + public: + /** + * @brief Constructs a gamma distribution with parameters + * @f$ \alpha @f$ and @f$ \beta @f$. + */ + explicit + gamma_distribution(_RealType __alpha = _RealType(1), + _RealType __beta = _RealType(1)) + : _M_param(__alpha, __beta) + { } + + explicit + gamma_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + * + * Does nothing for the gamma distribution. + */ + void + reset() { } + + /** + * @brief Returns the @f$ \alpha @f$ of the distribution. + */ + _RealType + alpha() const + { return _M_param.alpha(); } + + /** + * @brief Returns the @f$ \beta @f$ of the distribution. + */ + _RealType + beta() const + { return _M_param.beta(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two gamma distributions have the same + * parameters. + */ + template<typename _RealType> + bool + operator==(const gamma_distribution<_RealType>& __d1, + const gamma_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %gamma_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %gamma_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RealType>& __x); + + /** + * @brief Extracts a %gamma_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %gamma_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + gamma_distribution<_RealType>& __x); + + + /** + * @brief A weibull_distribution random number distribution. + * + * The formula for the normal probability density function is + * @f$ p(x|\alpha,\beta) = \frac{a}{b} (frac{x}{b})^{a-1} + * \exp{(-(frac{x}{b})^a)} @f$. + */ + template<typename _RealType = double> + class weibull_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef weibull_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __a = _RealType(1), + _RealType __b = _RealType(1)) + : _M_a(__a), _M_b(__b) + { } + + _RealType + a() const + { return _M_a; } + + _RealType + b() const + { return _M_b; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); } + + private: + _RealType _M_a; + _RealType _M_b; + }; + + explicit + weibull_distribution(_RealType __a = _RealType(1), + _RealType __b = _RealType(1)) + : _M_param(__a, __b) + { } + + explicit + weibull_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Return the @f$ a @f$ parameter of the distribution. + */ + _RealType + a() const + { return _M_param.a(); } + + /** + * @brief Return the @f$ b @f$ parameter of the distribution. + */ + _RealType + b() const + { return _M_param.b(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + return __p.b() * std::pow(-std::log(__aurng()), + result_type(1) / __p.a()); + } + + private: + param_type _M_param; + }; + + /** + * @brief Return true if two Weibull distributions have the same + * parameters. + */ + template<typename _RealType> + bool + operator==(const weibull_distribution<_RealType>& __d1, + const weibull_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %weibull_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %weibull_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const weibull_distribution<_RealType>& __x); + + /** + * @brief Extracts a %weibull_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %weibull_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + weibull_distribution<_RealType>& __x); + + + /** + * @brief A extreme_value_distribution random number distribution. + * + * The formula for the normal probability mass function is + * @f$ p(x|a,b) = \frac{1}{b} + * \exp( \frac{a-x}{b} - \exp(\frac{a-x}{b})) @f$ + */ + template<typename _RealType = double> + class extreme_value_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef extreme_value_distribution<_RealType> distribution_type; + + explicit + param_type(_RealType __a = _RealType(0), + _RealType __b = _RealType(1)) + : _M_a(__a), _M_b(__b) + { } + + _RealType + a() const + { return _M_a; } + + _RealType + b() const + { return _M_b; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_a == __p2._M_a) && (__p1._M_b == __p2._M_b); } + + private: + _RealType _M_a; + _RealType _M_b; + }; + + explicit + extreme_value_distribution(_RealType __a = _RealType(0), + _RealType __b = _RealType(1)) + : _M_param(__a, __b) + { } + + explicit + extreme_value_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Return the @f$ a @f$ parameter of the distribution. + */ + _RealType + a() const + { return _M_param.a(); } + + /** + * @brief Return the @f$ b @f$ parameter of the distribution. + */ + _RealType + b() const + { return _M_param.b(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return std::numeric_limits<result_type>::min(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + private: + param_type _M_param; + }; + + /** + * + */ + template<typename _RealType> + bool + operator==(const extreme_value_distribution<_RealType>& __d1, + const extreme_value_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /** + * @brief Inserts a %extreme_value_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %extreme_value_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const extreme_value_distribution<_RealType>& __x); + + /** + * @brief Extracts a %extreme_value_distribution random number + * distribution @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %extreme_value_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + extreme_value_distribution<_RealType>& __x); + + + /** + * @brief A discrete_distribution random number distribution. + * + * The formula for the discrete probability mass function is + * + */ + template<typename _IntType = int> + class discrete_distribution + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the range of the distribution. */ + typedef _IntType result_type; + /** Parameter type. */ + struct param_type + { + typedef discrete_distribution<_IntType> distribution_type; + friend class discrete_distribution<_IntType>; + + param_type() + : _M_prob(), _M_cp() + { _M_initialize(); } + + template<typename _InputIterator> + param_type(_InputIterator __wbegin, + _InputIterator __wend) + : _M_prob(__wbegin, __wend), _M_cp() + { _M_initialize(); } + + param_type(initializer_list<double> __wil) + : _M_prob(__wil.begin(), __wil.end()), _M_cp() + { _M_initialize(); } + + template<typename _Func> + param_type(size_t __nw, double __xmin, double __xmax, + _Func __fw); + + std::vector<double> + probabilities() const + { return _M_prob; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_prob == __p2._M_prob; } + + private: + void + _M_initialize(); + + std::vector<double> _M_prob; + std::vector<double> _M_cp; + }; + + discrete_distribution() + : _M_param() + { } + + template<typename _InputIterator> + discrete_distribution(_InputIterator __wbegin, + _InputIterator __wend) + : _M_param(__wbegin, __wend) + { } + + discrete_distribution(initializer_list<double> __wil) + : _M_param(__wil) + { } + + template<typename _Func> + discrete_distribution(size_t __nw, double __xmin, double __xmax, + _Func __fw) + : _M_param(__nw, __xmin, __xmax, __fw) + { } + + explicit + discrete_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Returns the probabilities of the distribution. + */ + std::vector<double> + probabilities() const + { return _M_param.probabilities(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return this->_M_param._M_prob.size() - 1; } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + /** + * @brief Inserts a %discrete_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %discrete_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IntType1>& __x); + + /** + * @brief Extracts a %discrete_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %discrete_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<typename _IntType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IntType1>& __x); + + private: + param_type _M_param; + }; + + /** + * + */ + template<typename _IntType> + bool + operator==(const discrete_distribution<_IntType>& __d1, + const discrete_distribution<_IntType>& __d2) + { return __d1.param() == __d2.param(); } + + + /** + * @brief A piecewise_constant_distribution random number distribution. + * + * The formula for the piecewise constant probability mass function is + * + */ + template<typename _RealType = double> + class piecewise_constant_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef piecewise_constant_distribution<_RealType> distribution_type; + friend class piecewise_constant_distribution<_RealType>; + + param_type(); + + template<typename _InputIteratorB, typename _InputIteratorW> + param_type(_InputIteratorB __bfirst, + _InputIteratorB __bend, + _InputIteratorW __wbegin); + + template<typename _Func> + param_type(initializer_list<_RealType> __bil, _Func __fw); + + template<typename _Func> + param_type(size_t __nw, _RealType __xmin, _RealType __xmax, + _Func __fw); + + std::vector<_RealType> + intervals() const + { return _M_int; } + + std::vector<double> + densities() const + { return _M_den; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_int == __p2._M_int) + && (__p1._M_den == __p2._M_den); } + + private: + void + _M_initialize(); + + std::vector<_RealType> _M_int; + std::vector<double> _M_den; + std::vector<double> _M_cp; + }; + + explicit + piecewise_constant_distribution() + : _M_param() + { } + + template<typename _InputIteratorB, typename _InputIteratorW> + piecewise_constant_distribution(_InputIteratorB __bfirst, + _InputIteratorB __bend, + _InputIteratorW __wbegin) + : _M_param(__bfirst, __bend, __wbegin) + { } + + template<typename _Func> + piecewise_constant_distribution(initializer_list<_RealType> __bil, + _Func __fw) + : _M_param(__bil, __fw) + { } + + template<typename _Func> + piecewise_constant_distribution(size_t __nw, + _RealType __xmin, _RealType __xmax, + _Func __fw) + : _M_param(__nw, __xmin, __xmax, __fw) + { } + + explicit + piecewise_constant_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Returns a vector of the intervals. + */ + std::vector<_RealType> + intervals() const + { return _M_param.intervals(); } + + /** + * @brief Returns a vector of the probability densities. + */ + std::vector<double> + densities() const + { return _M_param.densities(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return this->_M_param._M_int.front(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return this->_M_param._M_int.back(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + /** + * @brief Inserts a %piecewise_constan_distribution random + * number distribution @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %piecewise_constan_distribution random number + * distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RealType1>& __x); + + /** + * @brief Extracts a %piecewise_constan_distribution random + * number distribution @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %piecewise_constan_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + piecewise_constant_distribution<_RealType1>& __x); + + private: + param_type _M_param; + }; + + /** + * + */ + template<typename _RealType> + bool + operator==(const piecewise_constant_distribution<_RealType>& __d1, + const piecewise_constant_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + + /** + * @brief A piecewise_linear_distribution random number distribution. + * + * The formula for the piecewise linear probability mass function is + * + */ + template<typename _RealType = double> + class piecewise_linear_distribution + { + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef piecewise_linear_distribution<_RealType> distribution_type; + friend class piecewise_linear_distribution<_RealType>; + + param_type(); + + template<typename _InputIteratorB, typename _InputIteratorW> + param_type(_InputIteratorB __bfirst, + _InputIteratorB __bend, + _InputIteratorW __wbegin); + + template<typename _Func> + param_type(initializer_list<_RealType> __bil, _Func __fw); + + template<typename _Func> + param_type(size_t __nw, _RealType __xmin, _RealType __xmax, + _Func __fw); + + std::vector<_RealType> + intervals() const + { return _M_int; } + + std::vector<double> + densities() const + { return _M_den; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return (__p1._M_int == __p2._M_int) + && (__p1._M_den == __p2._M_den); } + + private: + void + _M_initialize(); + + std::vector<_RealType> _M_int; + std::vector<double> _M_den; + std::vector<double> _M_cp; + std::vector<double> _M_m; + }; + + explicit + piecewise_linear_distribution() + : _M_param() + { } + + template<typename _InputIteratorB, typename _InputIteratorW> + piecewise_linear_distribution(_InputIteratorB __bfirst, + _InputIteratorB __bend, + _InputIteratorW __wbegin) + : _M_param(__bfirst, __bend, __wbegin) + { } + + template<typename _Func> + piecewise_linear_distribution(initializer_list<_RealType> __bil, + _Func __fw) + : _M_param(__bil, __fw) + { } + + template<typename _Func> + piecewise_linear_distribution(size_t __nw, + _RealType __xmin, _RealType __xmax, + _Func __fw) + : _M_param(__nw, __xmin, __xmax, __fw) + { } + + explicit + piecewise_linear_distribution(const param_type& __p) + : _M_param(__p) + { } + + /** + * Resets the distribution state. + */ + void + reset() + { } + + /** + * @brief Return the intervals of the distribution. + */ + std::vector<_RealType> + intervals() const + { return _M_param.intervals(); } + + /** + * @brief Return a vector of the probability densities of the + * distribution. + */ + std::vector<double> + densities() const + { return _M_param.densities(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return this->_M_param._M_int.front(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return this->_M_param._M_int.back(); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return this->operator()(__urng, this->param()); } + + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + /** + * @brief Inserts a %piecewise_linear_distribution random number + * distribution @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %piecewise_linear_distribution random number + * distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RealType1>& __x); + + /** + * @brief Extracts a %piecewise_linear_distribution random number + * distribution @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %piecewise_linear_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error + * state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + piecewise_linear_distribution<_RealType1>& __x); + + private: + param_type _M_param; + }; + + /** + * + */ + template<typename _RealType> + bool + operator==(const piecewise_linear_distribution<_RealType>& __d1, + const piecewise_linear_distribution<_RealType>& __d2) + { return __d1.param() == __d2.param(); } + + /* @} */ // group std_random_distributions_poisson + + /* @} */ // group std_random_distributions + + /** + * @addtogroup std_random_utilities Random Number Utilities + * @ingroup std_random + * @{ + */ + + /** + * @brief The seed_seq class generates sequences of seeds for random + * number generators. + */ + class seed_seq + { + + public: + /** The type of the seed vales. */ + typedef uint_least32_t result_type; + + /** Default constructor. */ + seed_seq() + : _M_v() + { } + + template<typename _IntType> + seed_seq(std::initializer_list<_IntType> il); + + template<typename _InputIterator> + seed_seq(_InputIterator __begin, _InputIterator __end); + + // generating functions + template<typename _RandomAccessIterator> + void + generate(_RandomAccessIterator __begin, _RandomAccessIterator __end); + + // property functions + size_t size() const + { return _M_v.size(); } + + template<typename OutputIterator> + void + param(OutputIterator __dest) const + { std::copy(_M_v.begin(), _M_v.end(), __dest); } + + private: + /// + vector<result_type> _M_v; + }; + + /* @} */ // group std_random_utilities + + /* @} */ // group std_random + +} + diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc new file mode 100644 index 00000000000..0c4f7a4420d --- /dev/null +++ b/libstdc++-v3/include/bits/random.tcc @@ -0,0 +1,2794 @@ +// random number generation (out of line) -*- C++ -*- + +// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file bits/random.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#include <iostream> +#include <vector> +#include <numeric> +#include <algorithm> + +namespace std +{ + + /* + * (Further) implementation-space details. + */ + namespace __detail + { + // General case for x = (ax + c) mod m -- use Schrage's algorithm to + // avoid integer overflow. + // + // Because a and c are compile-time integral constants the compiler + // kindly elides any unreachable paths. + // + // Preconditions: a > 0, m > 0. + // + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool> + struct _Mod + { + static _Tp + __calc(_Tp __x) + { + if (__a == 1) + __x %= __m; + else + { + static const _Tp __q = __m / __a; + static const _Tp __r = __m % __a; + + _Tp __t1 = __a * (__x % __q); + _Tp __t2 = __r * (__x / __q); + if (__t1 >= __t2) + __x = __t1 - __t2; + else + __x = __m - __t2 + __t1; + } + + if (__c != 0) + { + const _Tp __d = __m - __x; + if (__d > __c) + __x += __c; + else + __x = __c - __d; + } + return __x; + } + }; + + // Special case for m == 0 -- use unsigned integer overflow as modulo + // operator. + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m> + struct _Mod<_Tp, __a, __c, __m, true> + { + static _Tp + __calc(_Tp __x) + { return __a * __x + __c; } + }; + } // namespace __detail + + /** + * Seeds the LCR with integral value @p __x0, adjusted so that the + * ring identity is never a member of the convergence set. + */ + template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + void + linear_congruential_engine<_UIntType, __a, __c, __m>:: + seed(_UIntType __x0) + { + if ((__detail::__mod<_UIntType, 1U, 0U, __m>(__c) == 0U) + && (__detail::__mod<_UIntType, 1U, 0U, __m>(__x0) == 0U)) + _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(1U); + else + _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(__x0); + } + + /** + * Seeds the LCR engine with a value generated by @p __g. + */ + template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + void + linear_congruential_engine<_UIntType, __a, __c, __m>:: + seed(seed_seq& __q) + { + const _UIntType __k = (std::log2(__m) + 31) / 32; + _UIntType __arr[__k + 3]; + __q.generate(__arr + 0, __arr + 3); + _UIntType __factor = 1U; + _UIntType __sum = 0U; + for (size_t __i = 0; __i < __k; ++__i) + { + __sum += __arr[__i + 3] * __factor; + __factor *= __detail::_Shift<_UIntType, 32>::__value; + } + + if ((__detail::__mod<_UIntType, 1U, 0U, __m>(__c) == 0U) + && (__detail::__mod<_UIntType, 1U, 0U, __m>(__sum) == 0U)) + _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(1U); + else + _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(__sum); + } + + /** + * Seeds the LCR engine with a value generated by @p __g. + */ + template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + template<typename _Gen> + void + linear_congruential_engine<_UIntType, __a, __c, __m>:: + seed(_Gen& __g, false_type) + { + _UIntType __x0 = __g(); + if ((__detail::__mod<_UIntType, 1U, 0U, __m>(__c) == 0U) + && (__detail::__mod<_UIntType, 1U, 0U, __m>(__x0) == 0U)) + _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(1U); + else + _M_x = __detail::__mod<_UIntType, 1U, 0U, __m>(__x0); + } + + /** + * Gets the next generated value in sequence. + */ + template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + typename linear_congruential_engine<_UIntType, __a, __c, __m>:: + result_type + linear_congruential_engine<_UIntType, __a, __c, __m>:: + operator()() + { + _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x); + return _M_x; + } + + template<typename _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_engine<_UIntType, + __a, __c, __m>& __lcr) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + __os.flags(__ios_base::dec + | __ios_base::fixed + | __ios_base::left); + __os.fill(__os.widen(' ')); + + __os << __lcr._M_x; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<typename _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_engine<_UIntType, __a, __c, __m>& __lcr) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec); + + __is >> __lcr._M_x; + + __is.flags(__flags); + return __is; + } + + + template<typename _UIntType, + size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, + _UIntType __f> + void + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, + __s, __b, __t, __c, __l, __f>:: + seed(result_type __sd) + { + _M_x[0] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__sd); + + for (size_t __i = 1; __i < state_size; ++__i) + { + _UIntType __x = _M_x[__i - 1]; + __x ^= __x >> (__w - 2); + __x *= __f; + __x += __i; + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__x); + } + _M_p = state_size; + } + + template<typename _UIntType, + size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, + _UIntType __f> + void + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, + __s, __b, __t, __c, __l, __f>:: + seed(seed_seq& __q) + { + const _UIntType __upper_mask = (~_UIntType()) << __r; + const size_t __k = (__w + 31) / 32; + _UIntType __arr[__k * __n]; + __q.generate(__arr + 0, __arr + __k * __n); + + bool __zero = true; + for (size_t __i = 0; __i < state_size; ++__i) + { + _UIntType __factor = 1U; + _UIntType __sum = 0U; + for (size_t __j = 0; __j < __k; ++__j) + { + __sum += __arr[__i * __k + __j] * __factor; + __factor *= __detail::_Shift<_UIntType, 32>::__value; + } + _M_x[__i] = __detail::__mod<_UIntType, 1U, 0U, + __detail::_Shift<_UIntType, __w>::__value>(__sum); + + if (__zero) + { + if (__i == 0) + { + if ((_M_x[0] & __upper_mask) != 0U) + __zero = false; + } + else if (_M_x[__i] != 0U) + __zero = false; + } + } + if (__zero) + _M_x[0] = __detail::_Shift<_UIntType, __w - 1U>::__value; + } + + template<typename _UIntType, size_t __w, + size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, + _UIntType __f> + typename + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, + __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, + __s, __b, __t, __c, __l, __f>:: + operator()() + { + // Reload the vector - cost is O(n) amortized over n calls. + if (_M_p >= state_size) + { + const _UIntType __upper_mask = (~_UIntType()) << __r; + const _UIntType __lower_mask = ~__upper_mask; + + for (size_t __k = 0; __k < (__n - __m); ++__k) + { + _UIntType __y = ((_M_x[__k] & __upper_mask) + | (_M_x[__k + 1] & __lower_mask)); + _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + } + + for (size_t __k = (__n - __m); __k < (__n - 1); ++__k) + { + _UIntType __y = ((_M_x[__k] & __upper_mask) + | (_M_x[__k + 1] & __lower_mask)); + _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + } + + _UIntType __y = ((_M_x[__n - 1] & __upper_mask) + | (_M_x[0] & __lower_mask)); + _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + _M_p = 0; + } + + // Calculate o(x(i)). + result_type __z = _M_x[_M_p++]; + __z ^= (__z >> __u) & __d; + __z ^= (__z << __s) & __b; + __z ^= (__z << __t) & __c; + __z ^= (__z >> __l); + + return __z; + } + + template<typename _UIntType, size_t __w, + size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, + _UIntType __f, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UIntType, __w, __n, __m, + __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec + | __ios_base::fixed + | __ios_base::left); + __os.fill(__space); + + for (size_t __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<typename _UIntType, size_t __w, + size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, + _UIntType __f, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UIntType, __w, __n, __m, + __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (size_t __i = 0; __i < __n; ++__i) + __is >> __x._M_x[__i]; + + __is.flags(__flags); + return __is; + } + + + template<typename _UIntType, size_t __w, size_t __s, size_t __r> + void + subtract_with_carry_engine<_UIntType, __w, __s, __r>:: + seed(result_type __value) + { + if (__value == 0) + __value = default_seed; + + std::linear_congruential_engine<result_type, 40014U, 0U, 2147483563U> + __lcg(__value); + + // I hope this is right. The "10000" tests work for the ranluxen. + const size_t __n = (word_size + 31) / 32; + + for (size_t __i = 0; __i < long_lag; ++__i) + { + _UIntType __sum = 0U; + _UIntType __factor = 1U; + for (size_t __j = 0; __j < __n; ++__j) + { + __sum += __detail::__mod<__detail::_UInt32Type, 1, 0, 0> + (__lcg()) * __factor; + __factor *= __detail::_Shift<_UIntType, 32>::__value; + } + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, _S_modulus>(__sum); + } + _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; + _M_p = 0; + } + + template<typename _UIntType, size_t __w, size_t __s, size_t __r> + void + subtract_with_carry_engine<_UIntType, __w, __s, __r>:: + seed(seed_seq& __q) + { + const size_t __n = (word_size + 31) / 32; + unsigned int __arr[long_lag + __n]; + __q.generate(__arr + 0, __arr + long_lag + __n); + + for (size_t __i = 0; __i < long_lag; ++__i) + { + _UIntType __sum = 0U; + _UIntType __factor = 1U; + for (size_t __j = 0; __j < __n; ++__j) + { + __sum += __detail::__mod<__detail::_UInt32Type, 1, 0, 0> + (__arr[__i * __n + __j]) * __factor; + __factor *= __detail::_Shift<_UIntType, 32>::__value; + } + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, _S_modulus>(__sum); + } + _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; + _M_p = 0; + } + + template<typename _UIntType, size_t __w, size_t __s, size_t __r> + typename subtract_with_carry_engine<_UIntType, __w, __s, __r>:: + result_type + subtract_with_carry_engine<_UIntType, __w, __s, __r>:: + operator()() + { + // Derive short lag index from current index. + long __ps = _M_p - short_lag; + if (__ps < 0) + __ps += long_lag; + + // Calculate new x(i) without overflow or division. + // NB: Thanks to the requirements for _UIntType, _M_x[_M_p] + _M_carry + // cannot overflow. + _UIntType __xi; + if (_M_x[__ps] >= _M_x[_M_p] + _M_carry) + { + __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry; + _M_carry = 0; + } + else + { + __xi = _S_modulus - _M_x[_M_p] - _M_carry + _M_x[__ps]; + _M_carry = 1; + } + _M_x[_M_p] = __xi; + + // Adjust current index to loop around in ring buffer. + if (++_M_p >= long_lag) + _M_p = 0; + + return __xi; + } + + template<typename _UIntType, size_t __w, size_t __s, size_t __r, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UIntType, + __w, __s, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec + | __ios_base::fixed + | __ios_base::left); + __os.fill(__space); + + for (size_t __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 _UIntType, size_t __w, size_t __s, size_t __r, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (size_t __i = 0; __i < __r; ++__i) + __is >> __x._M_x[__i]; + __is >> __x._M_carry; + + __is.flags(__flags); + return __is; + } + + + template<typename _RandomNumberEngine, size_t __p, size_t __r> + typename discard_block_engine<_RandomNumberEngine, + __p, __r>::result_type + discard_block_engine<_RandomNumberEngine, __p, __r>:: + operator()() + { + if (_M_n >= used_block) + { + _M_b.discard(block_size - _M_n); + _M_n = 0; + } + ++_M_n; + return _M_b(); + } + + template<typename _RandomNumberEngine, size_t __p, size_t __r, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discard_block_engine<_RandomNumberEngine, + __p, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec + | __ios_base::fixed + | __ios_base::left); + __os.fill(__space); + + __os << __x.base() << __space << __x._M_n; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<typename _RandomNumberEngine, size_t __p, size_t __r, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discard_block_engine<_RandomNumberEngine, __p, __r>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_b >> __x._M_n; + + __is.flags(__flags); + return __is; + } + + + template<typename _RandomNumberEngine, size_t __w, typename _UIntType> + typename independent_bits_engine<_RandomNumberEngine, __w, _UIntType>:: + result_type + independent_bits_engine<_RandomNumberEngine, __w, _UIntType>:: + operator()() + { + const long double __r = static_cast<long double>(this->max()) + - static_cast<long double>(this->min()) + 1.0L; + const result_type __m = std::log2l(__r); + result_type __n, __n0, __y0, __y1, __s0, __s1; + for (size_t __i = 0; __i < 2; ++__i) + { + __n = (__w + __m - 1) / __m + __i; + __n0 = __n - __w % __n; + const result_type __w0 = __w / __n; + const result_type __w1 = __w0 + 1; + __s0 = 1UL << __w0; + __s1 = 1UL << __w1; + __y0 = __s0 * (__r / __s0); + __y1 = __s1 * (__r / __s1); + if (__r - __y0 <= __y0 / __n) + break; + } + + result_type __sum = 0; + for (size_t __k = 0; __k < __n0; ++__k) + { + result_type __u; + do + __u = _M_b() - this->min(); + while (__u >= __y0); + __sum = __s0 * __sum + + __u % __s0; + } + for (size_t __k = __n0; __k < __n; ++__k) + { + result_type __u; + do + __u = _M_b() - this->min(); + while (__u >= __y1); + __sum = __s1 * __sum + + __u % __s1; + } + return __sum; + } + + + template<typename _RandomNumberEngine, size_t __k> + typename shuffle_order_engine<_RandomNumberEngine, __k>::result_type + shuffle_order_engine<_RandomNumberEngine, __k>:: + operator()() + { + size_t __j = (__k * (_M_y - _M_b.min())) + / (_M_b.max() - _M_b.min() + 1); + _M_y = _M_v[__j]; + _M_v[__j] = _M_b(); + + return _M_y; + } + + template<typename _RandomNumberEngine, size_t __k, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const shuffle_order_engine<_RandomNumberEngine, __k>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec + | __ios_base::fixed + | __ios_base::left); + __os.fill(__space); + + __os << __x.base(); + for (size_t __i = 0; __i < __k; ++__i) + __os << __space << __x._M_v[__i]; + __os << __space << __x._M_y; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<typename _RandomNumberEngine, size_t __k, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + shuffle_order_engine<_RandomNumberEngine, __k>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_b; + for (size_t __i = 0; __i < __k; ++__i) + __is >> __x._M_v[__i]; + __is >> __x._M_y; + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename uniform_int_distribution<_IntType>::result_type + uniform_int_distribution<_IntType>:: + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, true_type) + { + // XXX Must be fixed to work well for *arbitrary* __urng.max(), + // __urng.min(), __max, __min. Currently works fine only in the + // most common case __urng.max() - __urng.min() >= __max - __min, + // with __urng.max() > __urng.min() >= 0. + typedef typename __gnu_cxx::__add_unsigned<typename + _UniformRandomNumberGenerator::result_type>::__type __urntype; + typedef typename __gnu_cxx::__add_unsigned<result_type>::__type + __utype; + typedef typename __gnu_cxx::__conditional_type<(sizeof(__urntype) + > sizeof(__utype)), + __urntype, __utype>::__type __uctype; + + result_type __ret; + + const __urntype __urnmin = __urng.min(); + const __urntype __urnmax = __urng.max(); + const __urntype __urnrange = __urnmax - __urnmin; + const __uctype __urange = __max - __min; + const __uctype __udenom = (__urnrange <= __urange + ? 1 : __urnrange / (__urange + 1)); + do + __ret = (__urntype(__urng()) - __urnmin) / __udenom; + while (__ret > __max - __min); + + return __ret + __min; + } + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int_distribution<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + + __os << __x.a() << __space << __x.b(); + + __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_distribution<_IntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _IntType __a, __b; + __is >> __a >> __b; + __x.param(typename uniform_int_distribution<_IntType>:: + param_type(__a, __b)); + + __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 uniform_real_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.a() << __space << __x.b(); + + __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_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + _RealType __a, __b; + __is >> __a >> __b; + __x.param(typename uniform_real_distribution<_RealType>:: + param_type(__a, __b)); + + __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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(std::numeric_limits<double>::digits10 + 1); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename geometric_distribution<_IntType>::result_type + geometric_distribution<_IntType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + // About the epsilon thing see this thread: + // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html + const double __naf = + (1 - std::numeric_limits<double>::epsilon()) / 2; + // The largest _RealType convertible to _IntType. + const double __thr = + std::numeric_limits<_IntType>::max() + __naf; + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + double __cand; + do + __cand = std::ceil(std::log(__aurng()) / __param._M_log_p); + while (__cand >= __thr); + + return result_type(__cand + __naf); + } + + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(std::numeric_limits<double>::digits10 + 1); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + geometric_distribution<_IntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + double __p; + __is >> __p; + __x.param(typename geometric_distribution<_IntType>::param_type(__p)); + + __is.flags(__flags); + return __is; + } + + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename negative_binomial_distribution<_IntType>::result_type + negative_binomial_distribution<_IntType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + typename gamma_distribution<>::param_type + __gamma_param(__p.k(), 1.0); + gamma_distribution<> __gamma(__gamma_param); + double __x = __gamma(__urng); + + typename poisson_distribution<result_type>::param_type + __poisson_param(__x * __p.p() / (1.0 - __p.p())); + poisson_distribution<result_type> __poisson(__poisson_param); + result_type __m = __poisson(__urng); + + return __m; + } + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const negative_binomial_distribution<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(std::numeric_limits<double>::digits10 + 1); + + __os << __x.k() << __space << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + negative_binomial_distribution<_IntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + _IntType __k; + double __p; + __is >> __k >> __p; + __x.param(typename negative_binomial_distribution<_IntType>:: + param_type(__k, __p)); + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType> + void + poisson_distribution<_IntType>::param_type:: + _M_initialize() + { +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_mean >= 12) + { + const double __m = std::floor(_M_mean); + _M_lm_thr = std::log(_M_mean); + _M_lfm = std::lgamma(__m + 1); + _M_sm = std::sqrt(__m); + + const double __pi_4 = 0.7853981633974483096156608458198757L; + const double __dx = std::sqrt(2 * __m * std::log(32 * __m + / __pi_4)); + _M_d = std::round(std::max(6.0, std::min(__m, __dx))); + const double __cx = 2 * __m + _M_d; + _M_scx = std::sqrt(__cx / 2); + _M_1cx = 1 / __cx; + + _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx); + _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2)) + / _M_d; + } + else +#endif + _M_lm_thr = std::exp(-_M_mean); + } + + /** + * A rejection algorithm when mean >= 12 and a simple method based + * upon the multiplication of uniform random variates otherwise. + * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 + * is defined. + * + * Reference: + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!). + */ + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename poisson_distribution<_IntType>::result_type + poisson_distribution<_IntType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, double> + __aurng(__urng); +#if _GLIBCXX_USE_C99_MATH_TR1 + if (__param.mean() >= 12) + { + double __x; + + // See comments above... + const double __naf = + (1 - std::numeric_limits<double>::epsilon()) / 2; + const double __thr = + std::numeric_limits<_IntType>::max() + __naf; + + const double __m = std::floor(__param.mean()); + // sqrt(pi / 2) + const double __spi_2 = 1.2533141373155002512078826424055226L; + const double __c1 = __param._M_sm * __spi_2; + const double __c2 = __param._M_c2b + __c1; + const double __c3 = __c2 + 1; + const double __c4 = __c3 + 1; + // e^(1 / 78) + const double __e178 = 1.0129030479320018583185514777512983L; + const double __c5 = __c4 + __e178; + const double __c = __param._M_cb + __c5; + const double __2cx = 2 * (2 * __m + __param._M_d); + + bool __reject = true; + do + { + const double __u = __c * __aurng(); + const double __e = -std::log(__aurng()); + + double __w = 0.0; + + if (__u <= __c1) + { + const double __n = _M_nd(__urng); + const double __y = -std::abs(__n) * __param._M_sm - 1; + __x = std::floor(__y); + __w = -__n * __n / 2; + if (__x < -__m) + continue; + } + else if (__u <= __c2) + { + const double __n = _M_nd(__urng); + const double __y = 1 + std::abs(__n) * __param._M_scx; + __x = std::ceil(__y); + __w = __y * (2 - __y) * __param._M_1cx; + if (__x > __param._M_d) + continue; + } + else if (__u <= __c3) + // NB: This case not in the book, nor in the Errata, + // but should be ok... + __x = -1; + else if (__u <= __c4) + __x = 0; + else if (__u <= __c5) + __x = 1; + else + { + const double __v = -std::log(__aurng()); + const double __y = __param._M_d + + __v * __2cx / __param._M_d; + __x = std::ceil(__y); + __w = -__param._M_d * __param._M_1cx * (1 + __y / 2); + } + + __reject = (__w - __e - __x * __param._M_lm_thr + > __param._M_lfm - std::lgamma(__x + __m + 1)); + + __reject |= __x + __m >= __thr; + + } while (__reject); + + return result_type(__x + __m + __naf); + } + else +#endif + { + _IntType __x = 0; + double __prod = 1.0; + + do + { + __prod *= __aurng(); + __x += 1; + } + while (__prod > __param._M_lm_thr); + + return __x - 1; + } + } + + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<double>::digits10 + 1); + + __os << __x.mean() << __space << __x._M_nd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + double __mean; + __is >> __mean >> __x._M_nd; + __x.param(typename poisson_distribution<_IntType>::param_type(__mean)); + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType> + void + binomial_distribution<_IntType>::param_type:: + _M_initialize() + { + const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; + + _M_easy = true; + +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_t * __p12 >= 8) + { + _M_easy = false; + const double __np = std::floor(_M_t * __p12); + const double __pa = __np / _M_t; + const double __1p = 1 - __pa; + + const double __pi_4 = 0.7853981633974483096156608458198757L; + const double __d1x = + std::sqrt(__np * __1p * std::log(32 * __np + / (81 * __pi_4 * __1p))); + _M_d1 = std::round(std::max(1.0, __d1x)); + const double __d2x = + std::sqrt(__np * __1p * std::log(32 * _M_t * __1p + / (__pi_4 * __pa))); + _M_d2 = std::round(std::max(1.0, __d2x)); + + // sqrt(pi / 2) + const double __spi_2 = 1.2533141373155002512078826424055226L; + _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np)); + _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p)); + _M_c = 2 * _M_d1 / __np; + _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2; + const double __a12 = _M_a1 + _M_s2 * __spi_2; + const double __s1s = _M_s1 * _M_s1; + _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p)) + * 2 * __s1s / _M_d1 + * std::exp(-_M_d1 * _M_d1 / (2 * __s1s))); + const double __s2s = _M_s2 * _M_s2; + _M_s = (_M_a123 + 2 * __s2s / _M_d2 + * std::exp(-_M_d2 * _M_d2 / (2 * __s2s))); + _M_lf = (std::lgamma(__np + 1) + + std::lgamma(_M_t - __np + 1)); + _M_lp1p = std::log(__pa / __1p); + + _M_q = -std::log(1 - (__p12 - __pa) / __1p); + } + else +#endif + _M_q = -std::log(1 - __p12); + } + + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename binomial_distribution<_IntType>::result_type + binomial_distribution<_IntType>:: + _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t) + { + _IntType __x = 0; + double __sum = 0.0; + __detail::_Adaptor<_UniformRandomNumberGenerator, double> + __aurng(__urng); + + do + { + const double __e = -std::log(__aurng()); + __sum += __e / (__t - __x); + __x += 1; + } + while (__sum <= _M_param._M_q); + + return __x - 1; + } + + /** + * A rejection algorithm when t * p >= 8 and a simple waiting time + * method - the second in the referenced book - otherwise. + * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 + * is defined. + * + * Reference: + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. X, Sect. 4 (+ Errata!). + */ + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename binomial_distribution<_IntType>::result_type + binomial_distribution<_IntType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + result_type __ret; + const _IntType __t = __param.t(); + const _IntType __p = __param.p(); + const double __p12 = __p <= 0.5 ? __p : 1.0 - __p; + __detail::_Adaptor<_UniformRandomNumberGenerator, double> + __aurng(__urng); + +#if _GLIBCXX_USE_C99_MATH_TR1 + if (!__param._M_easy) + { + double __x; + + // See comments above... + const double __naf = + (1 - std::numeric_limits<double>::epsilon()) / 2; + const double __thr = + std::numeric_limits<_IntType>::max() + __naf; + + const double __np = std::floor(__t * __p12); + + // sqrt(pi / 2) + const double __spi_2 = 1.2533141373155002512078826424055226L; + const double __a1 = __param._M_a1; + const double __a12 = __a1 + __param._M_s2 * __spi_2; + const double __a123 = __param._M_a123; + const double __s1s = __param._M_s1 * __param._M_s1; + const double __s2s = __param._M_s2 * __param._M_s2; + + bool __reject; + do + { + const double __u = __param._M_s * __aurng(); + + double __v; + + if (__u <= __a1) + { + const double __n = _M_nd(__urng); + const double __y = __param._M_s1 * std::abs(__n); + __reject = __y >= __param._M_d1; + if (!__reject) + { + const double __e = -std::log(__aurng()); + __x = std::floor(__y); + __v = -__e - __n * __n / 2 + __param._M_c; + } + } + else if (__u <= __a12) + { + const double __n = _M_nd(__urng); + const double __y = __param._M_s2 * std::abs(__n); + __reject = __y >= __param._M_d2; + if (!__reject) + { + const double __e = -std::log(__aurng()); + __x = std::floor(-__y); + __v = -__e - __n * __n / 2; + } + } + else if (__u <= __a123) + { + const double __e1 = -std::log(__aurng()); + const double __e2 = -std::log(__aurng()); + + const double __y = __param._M_d1 + + 2 * __s1s * __e1 / __param._M_d1; + __x = std::floor(__y); + __v = (-__e2 + __param._M_d1 * (1 / (__t - __np) + -__y / (2 * __s1s))); + __reject = false; + } + else + { + const double __e1 = -std::log(__aurng()); + const double __e2 = -std::log(__aurng()); + + const double __y = __param._M_d2 + + 2 * __s2s * __e1 / __param._M_d2; + __x = std::floor(-__y); + __v = -__e2 - __param._M_d2 * __y / (2 * __s2s); + __reject = false; + } + + __reject = __reject || __x < -__np || __x > __t - __np; + if (!__reject) + { + const double __lfx = + std::lgamma(__np + __x + 1) + + std::lgamma(__t - (__np + __x) + 1); + __reject = __v > __param._M_lf - __lfx + + __x * __param._M_lp1p; + } + + __reject |= __x + __np >= __thr; + } + while (__reject); + + __x += __np + __naf; + + const _IntType __z = _M_waiting(__urng, __t - _IntType(__x)); + __ret = _IntType(__x) + __z; + } + else +#endif + __ret = _M_waiting(__urng, __t); + + if (__p12 != __p) + __ret = __t - __ret; + return __ret; + } + + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<double>::digits10 + 1); + + __os << __x.t() << __space << __x.p() + << __space << __x._M_nd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _IntType, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _IntType __t; + double __p; + __is >> __t >> __p >> __x._M_nd; + __x.param(typename binomial_distribution<_IntType>:: + param_type(__t, __p)); + + __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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.lambda(); + + __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, + exponential_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __lambda; + __is >> __lambda; + __x.param(typename exponential_distribution<_RealType>:: + param_type(__lambda)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + bool + operator==(const normal_distribution<_RealType>& __d1, + const normal_distribution<_RealType>& __d2) + { + if (__d1._M_param == __d2._M_param) + { + if (__d1._M_saved_available == __d2._M_saved_available) + { + if (__d1._M_saved_available + && __d1._M_saved == __d2._M_saved) + return true; + else if(!__d1._M_saved_available) + return true; + else + return false; + } + else + return false; + } + else + return false; + } + + /** + * Polar method due to Marsaglia. + * + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. V, Sect. 4.4. + */ + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename normal_distribution<_RealType>::result_type + normal_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + result_type __ret; + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + if (_M_saved_available) + { + _M_saved_available = false; + __ret = _M_saved; + } + else + { + result_type __x, __y, __r2; + do + { + __x = result_type(2.0) * __aurng() - 1.0; + __y = result_type(2.0) * __aurng() - 1.0; + __r2 = __x * __x + __y * __y; + } + while (__r2 > 1.0 || __r2 == 0.0); + + const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2); + _M_saved = __x * __mult; + _M_saved_available = true; + __ret = __y * __mult; + } + + __ret = __ret * __param.stddev() + __param.mean(); + return __ret; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.mean() << __space << __x.stddev() + << __space << __x._M_saved_available; + if (__x._M_saved_available) + __os << __space << __x._M_saved; + + __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + double __mean, __stddev; + __is >> __mean >> __stddev + >> __x._M_saved_available; + if (__x._M_saved_available) + __is >> __x._M_saved; + __x.param(typename normal_distribution<_RealType>:: + param_type(__mean, __stddev)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename lognormal_distribution<_RealType>::result_type + lognormal_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + _RealType __u, __v, __r2, __normal; + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + do + { + // Choose x,y in uniform square (-1,-1) to (+1,+1). + __u = 2 * __aurng() - 1; + __v = 2 * __aurng() - 1; + + // See if it is in the unit circle. + __r2 = __u * __u + __v * __v; + } + while (__r2 > 1 || __r2 == 0); + + __normal = __u * std::sqrt(-2 * std::log(__r2) / __r2); + + return std::exp(__p.s() * __normal + __p.m()); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.m() << __space << __x.s(); + + __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, + lognormal_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __m, __s; + __is >> __m >> __s; + __x.param(typename lognormal_distribution<_RealType>:: + param_type(__m, __s)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename chi_squared_distribution<_RealType>::result_type + chi_squared_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + typename gamma_distribution<_RealType>::param_type + __gamma_param(__p.n() / 2, 1.0); + gamma_distribution<_RealType> __gamma(__gamma_param); + return 2 * __gamma(__urng); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const chi_squared_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.n(); + + __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, + chi_squared_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __n; + __is >> __n; + __x.param(typename chi_squared_distribution<_RealType>:: + param_type(__n)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename cauchy_distribution<_RealType>::result_type + cauchy_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + _RealType __u; + do + { + __u = __aurng(); + } + while (__u == 0.5); + + return __p.a() + __p.b() * std::tan(M_PI * __u); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const cauchy_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.a() << __space << __x.b(); + + __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, + cauchy_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __a, __b; + __is >> __a >> __b; + __x.param(typename cauchy_distribution<_RealType>:: + param_type(__a, __b)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename fisher_f_distribution<_RealType>::result_type + fisher_f_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + gamma_distribution<_RealType> __gamma; + _RealType __ym = __gamma(__urng, + typename gamma_distribution<_RealType>::param_type(__p.m() / 2, 2)); + + _RealType __yn = __gamma(__urng, + typename gamma_distribution<_RealType>::param_type(__p.n() / 2, 2)); + + return (__ym * __p.n()) / (__yn * __p.m()); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const fisher_f_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.m() << __space << __x.n(); + + __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, + fisher_f_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __m, __n; + __is >> __m >> __n; + __x.param(typename fisher_f_distribution<_RealType>:: + param_type(__m, __n)); + + __is.flags(__flags); + return __is; + } + + + // + // This could be operator() for a Gaussian distribution. + // + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename student_t_distribution<_RealType>::result_type + student_t_distribution<_RealType>:: + _M_gaussian(_UniformRandomNumberGenerator& __urng, + const result_type __sigma) + { + _RealType __x, __y, __r2; + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + do + { + // Choose x,y in uniform square (-1,-1) to (+1,+1). + __x = 2 * __aurng() - 1; + __y = 2 * __aurng() - 1; + + // See if it is in the unit circle. + __r2 = __x * __x + __y * __y; + } + while (__r2 > 1 || __r2 == 0); + + // Box-Muller transform. + return __sigma * __y * std::sqrt(-2 * std::log(__r2) / __r2); + } + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename student_t_distribution<_RealType>::result_type + student_t_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + if (__param.n() <= 2.0) + { + _RealType __y1 = _M_gaussian(__urng, 1.0); + typename chi_squared_distribution<_RealType>::param_type + __chisq_param(__param.n()); + chi_squared_distribution<_RealType> __chisq(__chisq_param); + _RealType __y2 = __chisq(__urng); + + return __y1 / std::sqrt(__y2 / __param.n()); + } + else + { + _RealType __y1, __y2, __z; + do + { + __y1 = _M_gaussian(__urng, 1.0); + typename exponential_distribution<_RealType>::param_type + __exp_param(1.0 / (__param.n() / 2.0 - 1.0)); + exponential_distribution<_RealType> + __exponential(__exp_param); + __y2 = __exponential(__urng); + + __z = __y1 * __y1 / (__param.n() - 2.0); + } + while (1.0 - __z < 0.0 || std::exp(-__y2 - __z) > (1.0 - __z)); + + // Note that there is a typo in Knuth's formula, the line below + // is taken from the original paper of Marsaglia, Mathematics of + // Computation, 34 (1980), p 234-256 + return __y1 / std::sqrt((1.0 - 2.0 / __param.n()) * (1.0 - __z)); + } + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const student_t_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.n(); + + __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, + student_t_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __n; + __is >> __n; + __x.param(typename student_t_distribution<_RealType>::param_type(__n)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + void + gamma_distribution<_RealType>::param_type:: + _M_initialize() + { + if (_M_alpha >= 1) + _M_l_d = std::sqrt(2 * _M_alpha - 1); + else + _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha)) + * (1 - _M_alpha)); + } + + /** + * Cheng's rejection algorithm GB for alpha >= 1 and a modification + * of Vaduva's rejection from Weibull algorithm due to Devroye for + * alpha < 1. + * + * References: + * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral + * Shape Parameter." Applied Statistics, 26, 71-75, 1977. + * + * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection + * and Composition Procedures." Math. Operationsforschung and Statistik, + * Series in Statistics, 8, 545-576, 1977. + * + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!). + */ + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename gamma_distribution<_RealType>::result_type + gamma_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + result_type __x; + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + bool __reject; + const _RealType __alpha = __param.alpha(); + const _RealType __beta = __param.beta(); + if (__alpha >= 1) + { + // alpha - log(4) + const result_type __b = __alpha + - result_type(1.3862943611198906188344642429163531L); + const result_type __c = __alpha + __param._M_l_d; + const result_type __1l = 1 / __param._M_l_d; + + // 1 + log(9 / 2) + const result_type __k = 2.5040773967762740733732583523868748L; + + do + { + const result_type __u = __aurng() / __beta; + const result_type __v = __aurng() / __beta; + + const result_type __y = __1l * std::log(__v / (1 - __v)); + __x = __alpha * std::exp(__y); + + const result_type __z = __u * __v * __v; + const result_type __r = __b + __c * __y - __x; + + __reject = __r < result_type(4.5) * __z - __k; + if (__reject) + __reject = __r < std::log(__z); + } + while (__reject); + } + else + { + const result_type __c = 1 / __alpha; + + do + { + const result_type __z = -std::log(__aurng() / __beta); + const result_type __e = -std::log(__aurng() / __beta); + + __x = std::pow(__z, __c); + + __reject = __z + __e < __param._M_l_d + __x; + } + while (__reject); + } + + return __beta * __x; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.alpha() << __space << __x.beta(); + + __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, + gamma_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __alpha, __beta; + __is >> __alpha >> __beta; + __x.param(typename gamma_distribution<_RealType>:: + param_type(__alpha, __beta)); + + __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 weibull_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.a() << __space << __x.b(); + + __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, + weibull_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __a, __b; + __is >> __a >> __b; + __x.param(typename weibull_distribution<_RealType>:: + param_type(__a, __b)); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename extreme_value_distribution<_RealType>::result_type + extreme_value_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + return __p.a() - __p.b() * std::log(-std::log(__aurng())); + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const extreme_value_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + __os << __x.a() << __space << __x.b(); + + __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, + extreme_value_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __a, __b; + __is >> __a >> __b; + __x.param(typename extreme_value_distribution<_RealType>:: + param_type(__a, __b)); + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType> + void + discrete_distribution<_IntType>::param_type:: + _M_initialize() + { + if (_M_prob.size() < 2) + { + _M_prob.clear(); + _M_prob.push_back(1.0); + return; + } + + double __sum = std::accumulate(_M_prob.begin(), _M_prob.end(), 0.0); + // Now normalize the densities. + std::transform(_M_prob.begin(), _M_prob.end(), _M_prob.begin(), + std::bind2nd(std::divides<double>(), __sum)); + // Accumulate partial sums. + std::partial_sum(_M_prob.begin(), _M_prob.end(), + std::back_inserter(_M_cp)); + // Make sure the last cumulative probablility is one. + _M_cp[_M_cp.size() - 1] = 1.0; + } + + template<typename _IntType> + template<typename _Func> + discrete_distribution<_IntType>::param_type:: + param_type(size_t __nw, double __xmin, double __xmax, + _Func __fw) + : _M_prob(), _M_cp() + { + for (size_t __i = 0; __i < __nw; ++__i) + { + const double __x = ((__nw - __i - 0.5) * __xmin + + (__i + 0.5) * __xmax) / __nw; + _M_prob.push_back(__fw(__x)); + } + + _M_initialize(); + } + + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename discrete_distribution<_IntType>::result_type + discrete_distribution<_IntType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + const double __p = __aurng(); + auto __pos = std::lower_bound(__param._M_cp.begin(), + __param._M_cp.end(), __p); + if (__pos == __param._M_cp.end()) + return 0; + const size_t __i = __pos - __param._M_cp.begin(); + + return __i; + } + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<double>::digits10 + 1); + + std::vector<double> __prob = __x.probabilities(); + __os << __prob.size(); + for (auto __dit = __prob.begin(); __dit != __prob.end(); ++__dit) + __os << __space << *__dit; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IntType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + size_t __n; + __is >> __n; + + std::vector<double> __prob_vec; + for (; __n != 0; --__n) + { + double __prob; + __is >> __prob; + __prob_vec.push_back(__prob); + } + + __x.param(typename discrete_distribution<_IntType>:: + param_type(__prob_vec.begin(), __prob_vec.end())); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + void + piecewise_constant_distribution<_RealType>::param_type:: + _M_initialize() + { + if (_M_int.size() < 2) + { + _M_int.clear(); + _M_int.push_back(_RealType(0)); + _M_int.push_back(_RealType(1)); + + _M_den.clear(); + _M_den.push_back(1.0); + + return; + } + + double __sum = 0.0; + for (size_t __i = 0; __i < _M_den.size(); ++__i) + { + __sum += _M_den[__i] * (_M_int[__i + 1] - _M_int[__i]); + _M_cp.push_back(__sum); + } + + // Now normalize the densities... + std::transform(_M_den.begin(), _M_den.end(), _M_den.begin(), + std::bind2nd(std::divides<double>(), __sum)); + // ... and partial sums. + std::transform(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), + std::bind2nd(std::divides<double>(), __sum)); + // Make sure the last cumulative probablility is one. + _M_cp[_M_cp.size() - 1] = 1.0; + } + + template<typename _RealType> + piecewise_constant_distribution<_RealType>::param_type:: + param_type() + : _M_int(), _M_den(), _M_cp() + { + _M_initialize(); + } + + template<typename _RealType> + template<typename _InputIteratorB, typename _InputIteratorW> + piecewise_constant_distribution<_RealType>::param_type:: + param_type(_InputIteratorB __bbegin, + _InputIteratorB __bend, + _InputIteratorW __wbegin) + : _M_int(), _M_den(), _M_cp() + { + do + { + _M_int.push_back(*__bbegin); + ++__bbegin; + if (__bbegin != __bend) + { + _M_den.push_back(*__wbegin); + ++__wbegin; + } + } + while (__bbegin != __bend); + + _M_initialize(); + } + + template<typename _RealType> + template<typename _Func> + piecewise_constant_distribution<_RealType>::param_type:: + param_type(initializer_list<_RealType> __bil, _Func __fw) + : _M_int(), _M_den(), _M_cp() + { + for (auto __biter = __bil.begin(); __biter != __bil.end(); ++__biter) + _M_int.push_back(*__biter); + + for (size_t __i = 0; __i < _M_int.size() - 1; ++__i) + { + _RealType __x = 0.5 * (_M_int[__i] + _M_int[__i + 1]); + _M_den.push_back(__fw(__x)); + } + + _M_initialize(); + } + + template<typename _RealType> + template<typename _Func> + piecewise_constant_distribution<_RealType>::param_type:: + param_type(size_t __nw, _RealType __xmin, _RealType __xmax, + _Func __fw) + : _M_int(), _M_den(), _M_cp() + { + for (size_t __i = 0; __i <= __nw; ++__i) + { + const _RealType __x = ((__nw - __i) * __xmin + + __i * __xmax) / __nw; + _M_int.push_back(__x); + } + for (size_t __i = 0; __i < __nw; ++__i) + { + const _RealType __x = ((__nw - __i - 0.5) * __xmin + + (__i + 0.5) * __xmax) / __nw; + _M_den.push_back(__fw(__x)); + } + + _M_initialize(); + } + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename piecewise_constant_distribution<_RealType>::result_type + piecewise_constant_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + const double __p = __aurng(); + auto __pos = std::lower_bound(__param._M_cp.begin(), + __param._M_cp.end(), __p); + const size_t __i = __pos - __param._M_cp.begin(); + + return __param._M_int[__i] + + (__p - __param._M_cp[__i]) / __param._M_den[__i]; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + std::vector<_RealType> __int = __x.intervals(); + __os << __int.size() - 1; + + for (auto __xit = __int.begin(); __xit != __int.end(); ++__xit) + __os << __space << *__xit; + + std::vector<double> __den = __x.densities(); + for (auto __dit = __den.begin(); __dit != __den.end(); ++__dit) + __os << __space << *__dit; + + __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, + piecewise_constant_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + size_t __n; + __is >> __n; + + std::vector<_RealType> __int_vec; + for (size_t __i = 0; __i <= __n; ++__i) + { + _RealType __int; + __is >> __int; + __int_vec.push_back(__int); + } + + std::vector<double> __den_vec; + for (size_t __i = 0; __i < __n; ++__i) + { + double __den; + __is >> __den; + __den_vec.push_back(__den); + } + + __x.param(typename piecewise_constant_distribution<_RealType>:: + param_type(__int_vec.begin(), __int_vec.end(), __den_vec.begin())); + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + void + piecewise_linear_distribution<_RealType>::param_type:: + _M_initialize() + { + if (_M_int.size() < 2) + { + _M_int.clear(); + _M_int.push_back(_RealType(0)); + _M_int.push_back(_RealType(1)); + + _M_den.clear(); + _M_den.push_back(1.0); + _M_den.push_back(1.0); + + return; + } + + double __sum = 0.0; + for (size_t __i = 0; __i < _M_int.size() - 1; ++__i) + { + const _RealType __delta = _M_int[__i + 1] - _M_int[__i]; + __sum += 0.5 * (_M_den[__i + 1] + _M_den[__i]) * __delta; + _M_cp.push_back(__sum); + _M_m.push_back((_M_den[__i + 1] - _M_den[__i]) / __delta); + } + + // Now normalize the densities... + std::transform(_M_den.begin(), _M_den.end(), _M_den.begin(), + std::bind2nd(std::divides<double>(),__sum)); + // ... and partial sums... + std::transform(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), + std::bind2nd(std::divides<double>(), __sum)); + // ... and slopes. + std::transform(_M_m.begin(), _M_m.end(), _M_m.begin(), + std::bind2nd(std::divides<double>(), __sum)); + // Make sure the last cumulative probablility is one. + _M_cp[_M_cp.size() - 1] = 1.0; + } + + template<typename _RealType> + piecewise_linear_distribution<_RealType>::param_type:: + param_type() + : _M_int(), _M_den(), _M_cp(), _M_m() + { + _M_initialize(); + } + + template<typename _RealType> + template<typename _InputIteratorB, typename _InputIteratorW> + piecewise_linear_distribution<_RealType>::param_type:: + param_type(_InputIteratorB __bbegin, + _InputIteratorB __bend, + _InputIteratorW __wbegin) + : _M_int(), _M_den(), _M_cp(), _M_m() + { + for (; __bbegin != __bend; ++__bbegin, ++__wbegin) + { + _M_int.push_back(*__bbegin); + _M_den.push_back(*__wbegin); + } + + _M_initialize(); + } + + template<typename _RealType> + template<typename _Func> + piecewise_linear_distribution<_RealType>::param_type:: + param_type(initializer_list<_RealType> __bil, _Func __fw) + : _M_int(), _M_den(), _M_cp(), _M_m() + { + for (auto __biter = __bil.begin(); __biter != __bil.end(); ++__biter) + { + _M_int.push_back(*__biter); + _M_den.push_back(__fw(*__biter)); + } + + _M_initialize(); + } + + template<typename _RealType> + template<typename _Func> + piecewise_linear_distribution<_RealType>::param_type:: + param_type(size_t __nw, _RealType __xmin, _RealType __xmax, + _Func __fw) + : _M_int(), _M_den(), _M_cp(), _M_m() + { + for (size_t __i = 0; __i <= __nw; ++__i) + { + const _RealType __x = ((__nw - __i) * __xmin + + __i * __xmax) / __nw; + _M_int.push_back(__x); + _M_den.push_back(__fw(__x)); + } + + _M_initialize(); + } + + template<typename _RealType> + template<typename _UniformRandomNumberGenerator> + typename piecewise_linear_distribution<_RealType>::result_type + piecewise_linear_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) + { + result_type __x; + __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __aurng(__urng); + + const double __p = __aurng(); + auto __pos = std::lower_bound(__param._M_cp.begin(), + __param._M_cp.end(), __p); + const size_t __i = __pos - __param._M_cp.begin(); + const double __a = 0.5 * __param._M_m[__i]; + const double __b = __param._M_den[__i]; + const double __c = __param._M_cp[__i]; + const double __q = -0.5 * (__b +#if _GLIBCXX_USE_C99_MATH_TR1 + + std::copysign(std::sqrt(__b * __b + - 4.0 * __a * __c), __b)); +#else + + (__b < 0.0 ? -1.0 : 1.0) + * std::sqrt(__b * __b - 4.0 * __a * __c))); +#endif + const double __x0 = __param._M_int[__i]; + const double __x1 = __q / __a; + const double __x2 = __c / __q; + __x = std::max(__x0 + __x1, __x0 + __x2); + + return __x; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::digits10 + 1); + + std::vector<_RealType> __int = __x.intervals(); + __os << __int.size() - 1; + + for (auto __xit = __int.begin(); __xit != __int.end(); ++__xit) + __os << __space << *__xit; + + std::vector<double> __den = __x.densities(); + for (auto __dit = __den.begin(); __dit != __den.end(); ++__dit) + __os << __space << *__dit; + + __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, + piecewise_linear_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + size_t __n; + __is >> __n; + + std::vector<_RealType> __int_vec; + for (size_t __i = 0; __i <= __n; ++__i) + { + _RealType __int; + __is >> __int; + __int_vec.push_back(__int); + } + + std::vector<double> __den_vec; + for (size_t __i = 0; __i <= __n; ++__i) + { + double __den; + __is >> __den; + __den_vec.push_back(__den); + } + + __x.param(typename piecewise_linear_distribution<_RealType>:: + param_type(__int_vec.begin(), __int_vec.end(), __den_vec.begin())); + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType> + seed_seq::seed_seq(std::initializer_list<_IntType> __il) + { + for (auto __iter = __il.begin(); __iter != __il.end(); ++__iter) + _M_v.push_back(__detail::__mod<result_type, 1, 0, + __detail::_Shift<result_type, 32>::__value>(*__iter)); + } + + template<typename _InputIterator> + seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end) + { + for (_InputIterator __iter = __begin; __iter != __end; ++__iter) + _M_v.push_back(__detail::__mod<result_type, 1, 0, + __detail::_Shift<result_type, 32>::__value>(*__iter)); + } + + template<typename _RandomAccessIterator> + void + seed_seq::generate(_RandomAccessIterator __begin, + _RandomAccessIterator __end) + { + typedef typename iterator_traits<_RandomAccessIterator>::value_type + __Type; + + if (__begin == __end) + return; + + std::fill(__begin, __end, __Type(0x8b8b8b8bU)); + + const size_t __n = __end - __begin; + const size_t __s = _M_v.size(); + const size_t __t = (__n >= 623) ? 11 + : (__n >= 68) ? 7 + : (__n >= 39) ? 5 + : (__n >= 7) ? 3 + : (__n - 1) / 2; + const size_t __p = (__n - __t) / 2; + const size_t __q = __p + __t; + const size_t __m = std::max(__s + 1, __n); + + for (size_t __k = 0; __k < __m; ++__k) + { + __Type __arg = __begin[__k % __n] + ^ __begin[(__k + __p) % __n] + ^ __begin[(__k - 1) % __n]; + __Type __r1 = __arg ^ (__arg << 27); + __r1 = __detail::__mod<__Type, 1664525U, 0U, + __detail::_Shift<__Type, 32>::__value>(__r1); + __Type __r2 = __r1; + if (__k == 0) + __r2 += __s; + else if (__k <= __s) + __r2 += __k % __n + _M_v[__k - 1]; + else + __r2 += __k % __n; + __r2 = __detail::__mod<__Type, 1U, 0U, + __detail::_Shift<__Type, 32>::__value>(__r2); + __begin[(__k + __p) % __n] += __r1; + __begin[(__k + __q) % __n] += __r2; + __begin[__k % __n] = __r2; + } + + for (size_t __k = __m; __k < __m + __n; ++__k) + { + __Type __arg = __begin[__k % __n] + + __begin[(__k + __p) % __n] + + __begin[(__k - 1) % __n]; + __Type __r3 = __arg ^ (__arg << 27); + __r3 = __detail::__mod<__Type, 1566083941U, 0U, + __detail::_Shift<__Type, 32>::__value>(__r3); + __Type __r4 = __r3 - __k % __n; + __r4 = __detail::__mod<__Type, 1U, 0U, + __detail::_Shift<__Type, 32>::__value>(__r4); + __begin[(__k + __p) % __n] ^= __r4; + __begin[(__k + __q) % __n] ^= __r3; + __begin[__k % __n] = __r4; + } + } + + template<typename _RealType, size_t __bits, + typename _UniformRandomNumberGenerator> + _RealType + generate_canonical(_UniformRandomNumberGenerator& __urng) + { + const size_t __b + = std::min(static_cast<size_t>(std::numeric_limits<_RealType>::digits), + __bits); + const long double __r = static_cast<long double>(__urng.max()) + - static_cast<long double>(__urng.min()) + 1.0L; + const size_t __log2r = std::log2l(__r); + size_t __k = std::max<size_t>(1UL, (__b + __log2r - 1UL) / __log2r); + _RealType __sum = _RealType(0); + _RealType __tmp = _RealType(1); + for (; __k != 0; --__k) + { + __sum += _RealType(__urng() - __urng.min()) * __tmp; + __tmp *= __r; + } + return __sum / __tmp; + } + +} diff --git a/libstdc++-v3/include/std/random b/libstdc++-v3/include/std/random index 395604b246a..52a0b73cf33 100644 --- a/libstdc++-v3/include/std/random +++ b/libstdc++-v3/include/std/random @@ -56,18 +56,10 @@ #include <debug/debug.h> #include <type_traits> -#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) -# include <tr1_impl/random> -#else -# define _GLIBCXX_INCLUDE_AS_CXX0X -# define _GLIBCXX_BEGIN_NAMESPACE_TR1 -# define _GLIBCXX_END_NAMESPACE_TR1 -# define _GLIBCXX_TR1 -# include <tr1_impl/random> -# undef _GLIBCXX_TR1 -# undef _GLIBCXX_END_NAMESPACE_TR1 -# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 -# undef _GLIBCXX_INCLUDE_AS_CXX0X +#include <bits/random.h> + +#ifndef _GLIBCXX_EXPORT_TEMPLATE +# include <bits/random.tcc> #endif #endif // __GXX_EXPERIMENTAL_CXX0X__ diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random index 49a3b21cd81..6f6e3234b89 100644 --- a/libstdc++-v3/include/tr1/random +++ b/libstdc++-v3/include/tr1/random @@ -55,16 +55,12 @@ #include <tr1/cmath> #if defined(_GLIBCXX_INCLUDE_AS_TR1) -# include <tr1_impl/random> +# include <tr1/random.h> #else # define _GLIBCXX_INCLUDE_AS_TR1 -# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { -# define _GLIBCXX_END_NAMESPACE_TR1 } # define _GLIBCXX_TR1 tr1:: -# include <tr1_impl/random> +# include <tr1/random.h> # undef _GLIBCXX_TR1 -# undef _GLIBCXX_END_NAMESPACE_TR1 -# undef _GLIBCXX_BEGIN_NAMESPACE_TR1 # undef _GLIBCXX_INCLUDE_AS_TR1 #endif diff --git a/libstdc++-v3/include/tr1/random.h b/libstdc++-v3/include/tr1/random.h new file mode 100644 index 00000000000..5a0f6b741b6 --- /dev/null +++ b/libstdc++-v3/include/tr1/random.h @@ -0,0 +1,2436 @@ +// random number generation -*- C++ -*- + +// Copyright (C) 2007, 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** + * @file tr1/random.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#ifndef _GLIBCXX_TR1_RANDOM_H +#define _GLIBCXX_TR1_RANDOM_H 1 + +#pragma GCC system_header + +#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) +# error TR1 header cannot be included from C++0x header +#endif + +#include <cmath> +#include <cstdio> +#include <cstdlib> +#include <string> +#include <iosfwd> +#include <limits> +#include <ext/type_traits.h> +#include <ext/numeric_traits.h> +#include <bits/concept_check.h> +#include <debug/debug.h> +#include <tr1/type_traits> +#include <tr1/cmath> + +namespace std +{ +namespace tr1 +{ + + // [5.1] Random number generation + + /** + * @addtogroup tr1_random Random Number Generation + * A facility for generating random numbers on selected distributions. + * @{ + */ + + /* + * Implementation-space details. + */ + namespace __detail + { + template<typename _UIntType, int __w, + bool = __w < std::numeric_limits<_UIntType>::digits> + struct _Shift + { static const _UIntType __value = 0; }; + + template<typename _UIntType, int __w> + struct _Shift<_UIntType, __w, true> + { static const _UIntType __value = _UIntType(1) << __w; }; + + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool> + struct _Mod; + + // Dispatch based on modulus value to prevent divide-by-zero compile-time + // errors when m == 0. + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m> + inline _Tp + __mod(_Tp __x) + { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); } + + typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4), + unsigned, unsigned long>::__type _UInt32Type; + + /* + * An adaptor class for converting the output of any Generator into + * the input for a specific Distribution. + */ + template<typename _Engine, typename _Distribution> + struct _Adaptor + { + typedef typename remove_reference<_Engine>::type _BEngine; + typedef typename _BEngine::result_type _Engine_result_type; + typedef typename _Distribution::input_type result_type; + + public: + _Adaptor(const _Engine& __g) + : _M_g(__g) { } + + result_type + min() const + { + result_type __return_value; + if (is_integral<_Engine_result_type>::value + && is_integral<result_type>::value) + __return_value = _M_g.min(); + else + __return_value = result_type(0); + return __return_value; + } + + result_type + max() const + { + result_type __return_value; + if (is_integral<_Engine_result_type>::value + && is_integral<result_type>::value) + __return_value = _M_g.max(); + else if (!is_integral<result_type>::value) + __return_value = result_type(1); + else + __return_value = std::numeric_limits<result_type>::max() - 1; + return __return_value; + } + + /* + * Converts a value generated by the adapted random number generator + * into a value in the input domain for the dependent random number + * distribution. + * + * Because the type traits are compile time constants only the + * appropriate clause of the if statements will actually be emitted + * by the compiler. + */ + result_type + operator()() + { + result_type __return_value; + if (is_integral<_Engine_result_type>::value + && is_integral<result_type>::value) + __return_value = _M_g(); + else if (!is_integral<_Engine_result_type>::value + && !is_integral<result_type>::value) + __return_value = result_type(_M_g() - _M_g.min()) + / result_type(_M_g.max() - _M_g.min()); + else if (is_integral<_Engine_result_type>::value + && !is_integral<result_type>::value) + __return_value = result_type(_M_g() - _M_g.min()) + / result_type(_M_g.max() - _M_g.min() + result_type(1)); + else + __return_value = (((_M_g() - _M_g.min()) + / (_M_g.max() - _M_g.min())) + * std::numeric_limits<result_type>::max()); + return __return_value; + } + + private: + _Engine _M_g; + }; + + // Specialization for _Engine*. + template<typename _Engine, typename _Distribution> + struct _Adaptor<_Engine*, _Distribution> + { + typedef typename _Engine::result_type _Engine_result_type; + typedef typename _Distribution::input_type result_type; + + public: + _Adaptor(_Engine* __g) + : _M_g(__g) { } + + result_type + min() const + { + result_type __return_value; + if (is_integral<_Engine_result_type>::value + && is_integral<result_type>::value) + __return_value = _M_g->min(); + else + __return_value = result_type(0); + return __return_value; + } + + result_type + max() const + { + result_type __return_value; + if (is_integral<_Engine_result_type>::value + && is_integral<result_type>::value) + __return_value = _M_g->max(); + else if (!is_integral<result_type>::value) + __return_value = result_type(1); + else + __return_value = std::numeric_limits<result_type>::max() - 1; + return __return_value; + } + + result_type + operator()() + { + result_type __return_value; + if (is_integral<_Engine_result_type>::value + && is_integral<result_type>::value) + __return_value = (*_M_g)(); + else if (!is_integral<_Engine_result_type>::value + && !is_integral<result_type>::value) + __return_value = result_type((*_M_g)() - _M_g->min()) + / result_type(_M_g->max() - _M_g->min()); + else if (is_integral<_Engine_result_type>::value + && !is_integral<result_type>::value) + __return_value = result_type((*_M_g)() - _M_g->min()) + / result_type(_M_g->max() - _M_g->min() + result_type(1)); + else + __return_value = ((((*_M_g)() - _M_g->min()) + / (_M_g->max() - _M_g->min())) + * std::numeric_limits<result_type>::max()); + return __return_value; + } + + private: + _Engine* _M_g; + }; + } // namespace __detail + + /** + * Produces random numbers on a given distribution function using a + * non-uniform random number generation engine. + * + * @todo the engine_value_type needs to be studied more carefully. + */ + template<typename _Engine, typename _Dist> + class variate_generator + { + // Concept requirements. + __glibcxx_class_requires(_Engine, _CopyConstructibleConcept) + // __glibcxx_class_requires(_Engine, _EngineConcept) + // __glibcxx_class_requires(_Dist, _EngineConcept) + + public: + typedef _Engine engine_type; + typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type; + typedef _Dist distribution_type; + typedef typename _Dist::result_type result_type; + + // tr1:5.1.1 table 5.1 requirement + typedef typename __gnu_cxx::__enable_if< + is_arithmetic<result_type>::value, result_type>::__type _IsValidType; + + /** + * Constructs a variate generator with the uniform random number + * generator @p __eng for the random distribution @p __dist. + * + * @throws Any exceptions which may thrown by the copy constructors of + * the @p _Engine or @p _Dist objects. + */ + variate_generator(engine_type __eng, distribution_type __dist) + : _M_engine(__eng), _M_dist(__dist) { } + + /** + * Gets the next generated value on the distribution. + */ + result_type + operator()() + { return _M_dist(_M_engine); } + + /** + * WTF? + */ + template<typename _Tp> + result_type + operator()(_Tp __value) + { return _M_dist(_M_engine, __value); } + + /** + * Gets a reference to the underlying uniform random number generator + * object. + */ + engine_value_type& + engine() + { return _M_engine; } + + /** + * Gets a const reference to the underlying uniform random number + * generator object. + */ + const engine_value_type& + engine() const + { return _M_engine; } + + /** + * Gets a reference to the underlying random distribution. + */ + distribution_type& + distribution() + { return _M_dist; } + + /** + * Gets a const reference to the underlying random distribution. + */ + const distribution_type& + distribution() const + { return _M_dist; } + + /** + * Gets the closed lower bound of the distribution interval. + */ + result_type + min() const + { return this->distribution().min(); } + + /** + * Gets the closed upper bound of the distribution interval. + */ + result_type + max() const + { return this->distribution().max(); } + + private: + engine_value_type _M_engine; + distribution_type _M_dist; + }; + + + /** + * @addtogroup tr1_random_generators Random Number Generators + * @ingroup tr1_random + * + * These classes define objects which provide random or pseudorandom + * numbers, either from a discrete or a continuous interval. The + * random number generator supplied as a part of this library are + * all uniform random number generators which provide a sequence of + * random number uniformly distributed over their range. + * + * A number generator is a function object with an operator() that + * takes zero arguments and returns a number. + * + * A compliant random number generator must satisfy the following + * requirements. <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Random Number Generator Requirements</caption> + * <tr><td>To be documented.</td></tr> </table> + * + * @{ + */ + + /** + * @brief A model of a linear congruential random number generator. + * + * A random number generator that produces pseudorandom numbers using the + * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$. + * + * The template parameter @p _UIntType must be an unsigned integral type + * large enough to store values up to (__m-1). If the template parameter + * @p __m is 0, the modulus @p __m used is + * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template + * parameters @p __a and @p __c must be less than @p __m. + * + * The size of the state is @f$ 1 @f$. + */ + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + class linear_congruential + { + __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) + // __glibcpp_class_requires(__a < __m && __c < __m) + + public: + /** The type of the generated random value. */ + typedef _UIntType result_type; + + /** The multiplier. */ + static const _UIntType multiplier = __a; + /** An increment. */ + static const _UIntType increment = __c; + /** The modulus. */ + static const _UIntType modulus = __m; + + /** + * Constructs a %linear_congruential random number generator engine with + * seed @p __s. The default seed value is 1. + * + * @param __s The initial seed value. + */ + explicit + linear_congruential(unsigned long __x0 = 1) + { this->seed(__x0); } + + /** + * Constructs a %linear_congruential random number generator engine + * seeded from the generator function @p __g. + * + * @param __g The seed generator function. + */ + template<class _Gen> + linear_congruential(_Gen& __g) + { this->seed(__g); } + + /** + * Reseeds the %linear_congruential random number generator engine + * sequence to the seed @g __s. + * + * @param __s The new seed. + */ + void + seed(unsigned long __s = 1); + + /** + * Reseeds the %linear_congruential random number generator engine + * sequence using values from the generator function @p __g. + * + * @param __g the seed generator function. + */ + template<class _Gen> + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + /** + * Gets the smallest possible value in the output range. + * + * The minimum depends on the @p __c parameter: if it is zero, the + * minimum generated must be > 0, otherwise 0 is allowed. + */ + result_type + min() const + { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; } + + /** + * Gets the largest possible value in the output range. + */ + result_type + max() const + { return __m - 1; } + + /** + * Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * Compares two linear congruential random number generator + * objects of the same type for equality. + * + * @param __lhs A linear congruential random number generator object. + * @param __rhs Another linear congruential random number generator obj. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const linear_congruential& __lhs, + const linear_congruential& __rhs) + { return __lhs._M_x == __rhs._M_x; } + + /** + * Compares two linear congruential random number generator + * objects of the same type for inequality. + * + * @param __lhs A linear congruential random number generator object. + * @param __rhs Another linear congruential random number generator obj. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const linear_congruential& __lhs, + const linear_congruential& __rhs) + { return !(__lhs == __rhs); } + + /** + * 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. + * @returns __os. + */ + 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<_UIntType1, __a1, __c1, + __m1>& __lcr); + + /** + * Sets the state of the engine by reading its textual + * representation from @p __is. + * + * The textual representation must have been previously written using an + * output stream whose imbued locale and whose type's template + * specialization arguments _CharT and _Traits were the same as those of + * @p __is. + * + * @param __is The input stream. + * @param __lcr A % linear_congruential random number generator. + * @returns __is. + */ + 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<_UIntType1, __a1, __c1, __m1>& __lcr); + + private: + template<class _Gen> + void + seed(_Gen& __g, true_type) + { return seed(static_cast<unsigned long>(__g)); } + + template<class _Gen> + void + seed(_Gen& __g, false_type); + + _UIntType _M_x; + }; + + /** + * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller. + */ + typedef linear_congruential<unsigned long, 16807, 0, 2147483647> minstd_rand0; + + /** + * An alternative LCR (Lehmer Generator function) . + */ + typedef linear_congruential<unsigned long, 48271, 0, 2147483647> minstd_rand; + + + /** + * A generalized feedback shift register discrete random number generator. + * + * This algorithm avoids multiplication and division and is designed to be + * friendly to a pipelined architecture. If the parameters are chosen + * correctly, this generator will produce numbers with a very long period and + * fairly good apparent entropy, although still not cryptographically strong. + * + * The best way to use this generator is with the predefined mt19937 class. + * + * This algorithm was originally invented by Makoto Matsumoto and + * Takuji Nishimura. + * + * @var word_size The number of bits in each element of the state vector. + * @var state_size The degree of recursion. + * @var shift_size The period parameter. + * @var mask_bits The separation point bit index. + * @var parameter_a The last row of the twist matrix. + * @var output_u The first right-shift tempering matrix parameter. + * @var output_s The first left-shift tempering matrix parameter. + * @var output_b The first left-shift tempering matrix mask. + * @var output_t The second left-shift tempering matrix parameter. + * @var output_c The second left-shift tempering matrix mask. + * @var output_l The second right-shift tempering matrix parameter. + */ + 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) + + public: + // types + typedef _UIntType result_type; + + // parameter values + static const int word_size = __w; + static const int state_size = __n; + static const int shift_size = __m; + static const int mask_bits = __r; + static const _UIntType parameter_a = __a; + static const int output_u = __u; + static const int output_s = __s; + static const _UIntType output_b = __b; + static const int output_t = __t; + static const _UIntType output_c = __c; + static const int output_l = __l; + + // constructors and member function + mersenne_twister() + { seed(); } + + explicit + mersenne_twister(unsigned long __value) + { seed(__value); } + + template<class _Gen> + mersenne_twister(_Gen& __g) + { seed(__g); } + + void + seed() + { seed(5489UL); } + + void + seed(unsigned long __value); + + template<class _Gen> + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + result_type + min() const + { return 0; }; + + result_type + max() const + { return __detail::_Shift<_UIntType, __w>::__value - 1; } + + result_type + operator()(); + + /** + * Compares two % mersenne_twister random number generator objects of + * the same type for equality. + * + * @param __lhs A % mersenne_twister random number generator object. + * @param __rhs Another % mersenne_twister random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const mersenne_twister& __lhs, + const mersenne_twister& __rhs) + { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); } + + /** + * Compares two % mersenne_twister random number generator objects of + * the same type for inequality. + * + * @param __lhs A % mersenne_twister random number generator object. + * @param __rhs Another % mersenne_twister random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const mersenne_twister& __lhs, + const mersenne_twister& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a % mersenne_twister random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A % mersenne_twister random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + 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<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); + + /** + * Extracts the current state of a % mersenne_twister random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A % mersenne_twister random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + 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<_UIntType1, __w1, __n1, __m1, __r1, + __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); + + private: + template<class _Gen> + void + seed(_Gen& __g, true_type) + { return seed(static_cast<unsigned long>(__g)); } + + template<class _Gen> + void + seed(_Gen& __g, false_type); + + _UIntType _M_x[state_size]; + int _M_p; + }; + + /** + * The classic Mersenne Twister. + * + * Reference: + * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally + * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions + * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. + */ + typedef mersenne_twister< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18 + > mt19937; + + + /** + * @brief The Marsaglia-Zaman generator. + * + * This is a model of a Generalized Fibonacci discrete random number + * generator, sometimes referred to as the SWC generator. + * + * A discrete random number generator that produces pseudorandom + * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} - + * carry_{i-1}) \bmod m @f$. + * + * The size of the state is @f$ r @f$ + * and the maximum period of the generator is @f$ m^r - m^s -1 @f$. + * + * N1688[4.13] says "the template parameter _IntType shall denote an integral + * type large enough to store values up to m." + * + * @var _M_x The state of the generator. This is a ring buffer. + * @var _M_carry The carry. + * @var _M_p Current index of x(i - r). + */ + template<typename _IntType, _IntType __m, int __s, int __r> + class subtract_with_carry + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the generated random value. */ + typedef _IntType result_type; + + // parameter values + static const _IntType modulus = __m; + static const int long_lag = __r; + static const int short_lag = __s; + + /** + * Constructs a default-initialized % subtract_with_carry random number + * generator. + */ + subtract_with_carry() + { this->seed(); } + + /** + * Constructs an explicitly seeded % subtract_with_carry random number + * generator. + */ + explicit + subtract_with_carry(unsigned long __value) + { this->seed(__value); } + + /** + * Constructs a %subtract_with_carry random number generator engine + * seeded from the generator function @p __g. + * + * @param __g The seed generator function. + */ + template<class _Gen> + subtract_with_carry(_Gen& __g) + { this->seed(__g); } + + /** + * Seeds the initial state @f$ x_0 @f$ of the random number generator. + * + * N1688[4.19] modifies this as follows. If @p __value == 0, + * sets value to 19780503. In any case, with a linear + * congruential generator lcg(i) having parameters @f$ m_{lcg} = + * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value + * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m + * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$ + * set carry to 1, otherwise sets carry to 0. + */ + void + seed(unsigned long __value = 19780503); + + /** + * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry + * random number generator. + */ + template<class _Gen> + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + /** + * Gets the inclusive minimum value of the range of random integers + * returned by this generator. + */ + result_type + min() const + { return 0; } + + /** + * Gets the inclusive maximum value of the range of random integers + * returned by this generator. + */ + result_type + max() const + { return this->modulus - 1; } + + /** + * Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * Compares two % subtract_with_carry random number generator objects of + * the same type for equality. + * + * @param __lhs A % subtract_with_carry random number generator object. + * @param __rhs Another % subtract_with_carry random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const subtract_with_carry& __lhs, + const subtract_with_carry& __rhs) + { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); } + + /** + * Compares two % subtract_with_carry random number generator objects of + * the same type for inequality. + * + * @param __lhs A % subtract_with_carry random number generator object. + * @param __rhs Another % subtract_with_carry random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const subtract_with_carry& __lhs, + const subtract_with_carry& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a % subtract_with_carry random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A % subtract_with_carry random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + 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<_IntType1, __m1, __s1, + __r1>& __x); + + /** + * Extracts the current state of a % subtract_with_carry random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A % subtract_with_carry random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + 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<_IntType1, __m1, __s1, __r1>& __x); + + private: + template<class _Gen> + void + seed(_Gen& __g, true_type) + { return seed(static_cast<unsigned long>(__g)); } + + template<class _Gen> + void + seed(_Gen& __g, false_type); + + typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType; + + _UIntType _M_x[long_lag]; + _UIntType _M_carry; + int _M_p; + }; + + + /** + * @brief The Marsaglia-Zaman generator (floats version). + * + * @var _M_x The state of the generator. This is a ring buffer. + * @var _M_carry The carry. + * @var _M_p Current index of x(i - r). + * @var _M_npows Precomputed negative powers of 2. + */ + template<typename _RealType, int __w, int __s, int __r> + class subtract_with_carry_01 + { + public: + /** The type of the generated random value. */ + typedef _RealType result_type; + + // parameter values + static const int word_size = __w; + static const int long_lag = __r; + static const int short_lag = __s; + + /** + * Constructs a default-initialized % subtract_with_carry_01 random + * number generator. + */ + subtract_with_carry_01() + { + this->seed(); + _M_initialize_npows(); + } + + /** + * Constructs an explicitly seeded % subtract_with_carry_01 random number + * generator. + */ + explicit + subtract_with_carry_01(unsigned long __value) + { + this->seed(__value); + _M_initialize_npows(); + } + + /** + * Constructs a % subtract_with_carry_01 random number generator engine + * seeded from the generator function @p __g. + * + * @param __g The seed generator function. + */ + template<class _Gen> + subtract_with_carry_01(_Gen& __g) + { + this->seed(__g); + _M_initialize_npows(); + } + + /** + * Seeds the initial state @f$ x_0 @f$ of the random number generator. + */ + void + seed(unsigned long __value = 19780503); + + /** + * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry_01 + * random number generator. + */ + template<class _Gen> + void + seed(_Gen& __g) + { seed(__g, typename is_fundamental<_Gen>::type()); } + + /** + * Gets the minimum value of the range of random floats + * returned by this generator. + */ + result_type + min() const + { return 0.0; } + + /** + * Gets the maximum value of the range of random floats + * returned by this generator. + */ + result_type + max() const + { return 1.0; } + + /** + * Gets the next random number in the sequence. + */ + result_type + operator()(); + + /** + * Compares two % subtract_with_carry_01 random number generator objects + * of the same type for equality. + * + * @param __lhs A % subtract_with_carry_01 random number + * generator object. + * @param __rhs Another % subtract_with_carry_01 random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const subtract_with_carry_01& __lhs, + const subtract_with_carry_01& __rhs) + { + for (int __i = 0; __i < long_lag; ++__i) + if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n, + __rhs._M_x[__i])) + return false; + return true; + } + + /** + * Compares two % subtract_with_carry_01 random number generator objects + * of the same type for inequality. + * + * @param __lhs A % subtract_with_carry_01 random number + * generator object. + * + * @param __rhs Another % subtract_with_carry_01 random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const subtract_with_carry_01& __lhs, + const subtract_with_carry_01& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a % subtract_with_carry_01 random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A % subtract_with_carry_01 random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, int __w1, 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_01<_RealType1, __w1, __s1, + __r1>& __x); + + /** + * Extracts the current state of a % subtract_with_carry_01 random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A % subtract_with_carry_01 random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + template<typename _RealType1, int __w1, int __s1, int __r1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x); + + private: + template<class _Gen> + void + seed(_Gen& __g, true_type) + { return seed(static_cast<unsigned long>(__g)); } + + template<class _Gen> + void + seed(_Gen& __g, false_type); + + void + _M_initialize_npows(); + + static const int __n = (__w + 31) / 32; + + typedef __detail::_UInt32Type _UInt32Type; + _UInt32Type _M_x[long_lag][__n]; + _RealType _M_npows[__n]; + _UInt32Type _M_carry; + int _M_p; + }; + + typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 508. Bad parameters for ranlux64_base_01. + typedef subtract_with_carry_01<double, 48, 5, 12> ranlux64_base_01; + + + /** + * Produces random numbers from some base engine by discarding blocks of + * data. + * + * 0 <= @p __r <= @p __p + */ + template<class _UniformRandomNumberGenerator, int __p, int __r> + class discard_block + { + // __glibcxx_class_requires(typename base_type::result_type, + // ArithmeticTypeConcept) + + public: + /** The type of the underlying generator engine. */ + typedef _UniformRandomNumberGenerator base_type; + /** The type of the generated random value. */ + typedef typename base_type::result_type result_type; + + // parameter values + static const int block_size = __p; + static const int used_block = __r; + + /** + * Constructs a default %discard_block engine. + * + * The underlying engine is default constructed as well. + */ + discard_block() + : _M_n(0) { } + + /** + * Copy constructs a %discard_block engine. + * + * Copies an existing base class random number generator. + * @param rng An existing (base class) engine object. + */ + explicit + discard_block(const base_type& __rng) + : _M_b(__rng), _M_n(0) { } + + /** + * Seed constructs a %discard_block engine. + * + * Constructs the underlying generator engine seeded with @p __s. + * @param __s A seed value for the base class engine. + */ + explicit + discard_block(unsigned long __s) + : _M_b(__s), _M_n(0) { } + + /** + * Generator construct a %discard_block engine. + * + * @param __g A seed generator function. + */ + template<class _Gen> + discard_block(_Gen& __g) + : _M_b(__g), _M_n(0) { } + + /** + * Reseeds the %discard_block object with the default seed for the + * underlying base class generator engine. + */ + void seed() + { + _M_b.seed(); + _M_n = 0; + } + + /** + * Reseeds the %discard_block object with the given seed generator + * function. + * @param __g A seed generator function. + */ + template<class _Gen> + void seed(_Gen& __g) + { + _M_b.seed(__g); + _M_n = 0; + } + + /** + * Gets a const reference to the underlying generator engine object. + */ + const base_type& + base() const + { return _M_b; } + + /** + * Gets the minimum value in the generated random number range. + */ + result_type + min() const + { return _M_b.min(); } + + /** + * Gets the maximum value in the generated random number range. + */ + result_type + max() const + { return _M_b.max(); } + + /** + * Gets the next value in the generated random number sequence. + */ + result_type + operator()(); + + /** + * Compares two %discard_block random number generator objects of + * the same type for equality. + * + * @param __lhs A %discard_block random number generator object. + * @param __rhs Another %discard_block random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const discard_block& __lhs, const discard_block& __rhs) + { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); } + + /** + * Compares two %discard_block random number generator objects of + * the same type for inequality. + * + * @param __lhs A %discard_block random number generator object. + * @param __rhs Another %discard_block random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const discard_block& __lhs, const discard_block& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a %discard_block random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %discard_block random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + 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<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); + + /** + * Extracts the current state of a % subtract_with_carry random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %discard_block random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + 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<_UniformRandomNumberGenerator1, + __p1, __r1>& __x); + + private: + base_type _M_b; + int _M_n; + }; + + + /** + * James's luxury-level-3 integer adaptation of Luescher's generator. + */ + typedef discard_block< + subtract_with_carry<unsigned long, (1UL << 24), 10, 24>, + 223, + 24 + > ranlux3; + + /** + * James's luxury-level-4 integer adaptation of Luescher's generator. + */ + typedef discard_block< + subtract_with_carry<unsigned long, (1UL << 24), 10, 24>, + 389, + 24 + > ranlux4; + + typedef discard_block< + subtract_with_carry_01<float, 24, 10, 24>, + 223, + 24 + > ranlux3_01; + + typedef discard_block< + subtract_with_carry_01<float, 24, 10, 24>, + 389, + 24 + > ranlux4_01; + + + /** + * A random number generator adaptor class that combines two random number + * generator engines into a single output sequence. + */ + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2> + class xor_combine + { + // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1:: + // result_type, ArithmeticTypeConcept) + // __glibcxx_class_requires(typename _UniformRandomNumberGenerator2:: + // result_type, ArithmeticTypeConcept) + + public: + /** The type of the first underlying generator engine. */ + typedef _UniformRandomNumberGenerator1 base1_type; + /** The type of the second underlying generator engine. */ + typedef _UniformRandomNumberGenerator2 base2_type; + + private: + typedef typename base1_type::result_type _Result_type1; + typedef typename base2_type::result_type _Result_type2; + + public: + /** The type of the generated random value. */ + typedef typename __gnu_cxx::__conditional_type<(sizeof(_Result_type1) + > sizeof(_Result_type2)), + _Result_type1, _Result_type2>::__type result_type; + + // parameter values + static const int shift1 = __s1; + static const int shift2 = __s2; + + // constructors and member function + xor_combine() + : _M_b1(), _M_b2() + { _M_initialize_max(); } + + xor_combine(const base1_type& __rng1, const base2_type& __rng2) + : _M_b1(__rng1), _M_b2(__rng2) + { _M_initialize_max(); } + + xor_combine(unsigned long __s) + : _M_b1(__s), _M_b2(__s + 1) + { _M_initialize_max(); } + + template<class _Gen> + xor_combine(_Gen& __g) + : _M_b1(__g), _M_b2(__g) + { _M_initialize_max(); } + + void + seed() + { + _M_b1.seed(); + _M_b2.seed(); + } + + template<class _Gen> + void + seed(_Gen& __g) + { + _M_b1.seed(__g); + _M_b2.seed(__g); + } + + const base1_type& + base1() const + { return _M_b1; } + + const base2_type& + base2() const + { return _M_b2; } + + result_type + min() const + { return 0; } + + result_type + max() const + { return _M_max; } + + /** + * Gets the next random number in the sequence. + */ + // NB: Not exactly the TR1 formula, per N2079 instead. + result_type + operator()() + { + return ((result_type(_M_b1() - _M_b1.min()) << shift1) + ^ (result_type(_M_b2() - _M_b2.min()) << shift2)); + } + + /** + * Compares two %xor_combine random number generator objects of + * the same type for equality. + * + * @param __lhs A %xor_combine random number generator object. + * @param __rhs Another %xor_combine random number generator + * object. + * + * @returns true if the two objects are equal, false otherwise. + */ + friend bool + operator==(const xor_combine& __lhs, const xor_combine& __rhs) + { + return (__lhs.base1() == __rhs.base1()) + && (__lhs.base2() == __rhs.base2()); + } + + /** + * Compares two %xor_combine random number generator objects of + * the same type for inequality. + * + * @param __lhs A %xor_combine random number generator object. + * @param __rhs Another %xor_combine random number generator + * object. + * + * @returns true if the two objects are not equal, false otherwise. + */ + friend bool + operator!=(const xor_combine& __lhs, const xor_combine& __rhs) + { return !(__lhs == __rhs); } + + /** + * Inserts the current state of a %xor_combine random number + * generator engine @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %xor_combine random number generator engine. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + 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<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); + + /** + * Extracts the current state of a %xor_combine random number + * generator engine @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %xor_combine random number generator engine. + * + * @returns The input stream with the state of @p __x extracted or in + * an error state. + */ + 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<_UniformRandomNumberGenerator11, __s11, + _UniformRandomNumberGenerator21, __s21>& __x); + + private: + void + _M_initialize_max(); + + result_type + _M_initialize_max_aux(result_type, result_type, int); + + base1_type _M_b1; + base2_type _M_b2; + result_type _M_max; + }; + + + /** + * A standard interface to a platform-specific non-deterministic + * random number generator (if any are available). + */ + class random_device + { + public: + // types + typedef unsigned int result_type; + + // constructors, destructors and member functions + +#ifdef _GLIBCXX_USE_RANDOM_TR1 + + explicit + random_device(const std::string& __token = "/dev/urandom") + { + if ((__token != "/dev/urandom" && __token != "/dev/random") + || !(_M_file = std::fopen(__token.c_str(), "rb"))) + std::__throw_runtime_error(__N("random_device::" + "random_device(const std::string&)")); + } + + ~random_device() + { std::fclose(_M_file); } + +#else + + explicit + random_device(const std::string& __token = "mt19937") + : _M_mt(_M_strtoul(__token)) { } + + private: + static unsigned long + _M_strtoul(const std::string& __str) + { + unsigned long __ret = 5489UL; + if (__str != "mt19937") + { + const char* __nptr = __str.c_str(); + char* __endptr; + __ret = std::strtoul(__nptr, &__endptr, 0); + if (*__nptr == '\0' || *__endptr != '\0') + std::__throw_runtime_error(__N("random_device::_M_strtoul" + "(const std::string&)")); + } + return __ret; + } + + public: + +#endif + + result_type + min() const + { return std::numeric_limits<result_type>::min(); } + + result_type + max() const + { return std::numeric_limits<result_type>::max(); } + + double + entropy() const + { return 0.0; } + + result_type + operator()() + { +#ifdef _GLIBCXX_USE_RANDOM_TR1 + result_type __ret; + std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type), + 1, _M_file); + return __ret; +#else + return _M_mt(); +#endif + } + + private: + random_device(const random_device&); + void operator=(const random_device&); + +#ifdef _GLIBCXX_USE_RANDOM_TR1 + FILE* _M_file; +#else + mt19937 _M_mt; +#endif + }; + + /* @} */ // group tr1_random_generators + + /** + * @addtogroup tr1_random_distributions Random Number Distributions + * @ingroup tr1_random + * @{ + */ + + /** + * @addtogroup tr1_random_distributions_discrete Discrete Distributions + * @ingroup tr1_random_distributions + * @{ + */ + + /** + * @brief Uniform discrete distribution for random numbers. + * A discrete random distribution on the range @f$[min, max]@f$ with equal + * probability throughout the range. + */ + template<typename _IntType = int> + class uniform_int + { + __glibcxx_class_requires(_IntType, _IntegerConcept) + + public: + /** The type of the parameters of the distribution. */ + typedef _IntType input_type; + /** The type of the range of the distribution. */ + typedef _IntType result_type; + + public: + /** + * Constructs a uniform distribution object. + */ + explicit + uniform_int(_IntType __min = 0, _IntType __max = 9) + : _M_min(__min), _M_max(__max) + { + _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); + } + + /** + * Gets the inclusive lower bound of the distribution range. + */ + result_type + min() const + { return _M_min; } + + /** + * Gets the inclusive upper bound of the distribution range. + */ + result_type + max() const + { return _M_max; } + + /** + * Resets the distribution state. + * + * Does nothing for the uniform integer distribution. + */ + void + reset() { } + + /** + * Gets a uniformly distributed random number in the range + * @f$(min, max)@f$. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + typedef typename _UniformRandomNumberGenerator::result_type + _UResult_type; + return _M_call(__urng, _M_min, _M_max, + typename is_integral<_UResult_type>::type()); + } + + /** + * Gets a uniform random number in the range @f$[0, n)@f$. + * + * This function is aimed at use with std::random_shuffle. + */ + template<typename _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng, result_type __n) + { + typedef typename _UniformRandomNumberGenerator::result_type + _UResult_type; + return _M_call(__urng, 0, __n - 1, + typename is_integral<_UResult_type>::type()); + } + + /** + * Inserts a %uniform_int random number distribution @p __x into the + * output stream @p os. + * + * @param __os An output stream. + * @param __x A %uniform_int random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType1>& __x); + + /** + * Extracts a %uniform_int random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %uniform_int random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _IntType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_int<_IntType1>& __x); + + private: + template<typename _UniformRandomNumberGenerator> + result_type + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, true_type); + + template<typename _UniformRandomNumberGenerator> + result_type + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, false_type) + { + return result_type((__urng() - __urng.min()) + / (__urng.max() - __urng.min()) + * (__max - __min + 1)) + __min; + } + + _IntType _M_min; + _IntType _M_max; + }; + + + /** + * @brief A Bernoulli random number distribution. + * + * 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 + { + public: + typedef int input_type; + typedef bool result_type; + + public: + /** + * Constructs a Bernoulli distribution with likelihood @p p. + * + * @param __p [IN] The likelihood of a true result being returned. Must + * be in the interval @f$ [0, 1] @f$. + */ + explicit + bernoulli_distribution(double __p = 0.5) + : _M_p(__p) + { + _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0)); + } + + /** + * Gets the @p p parameter of the distribution. + */ + double + p() const + { return _M_p; } + + /** + * Resets the distribution state. + * + * Does nothing for a Bernoulli distribution. + */ + void + reset() { } + + /** + * Gets the next value in the Bernoullian sequence. + */ + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min())) + return true; + return false; + } + + /** + * Inserts a %bernoulli_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %bernoulli_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const bernoulli_distribution& __x); + + /** + * Extracts a %bernoulli_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %bernoulli_distribution random number generator engine. + * + * @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& __x) + { return __is >> __x._M_p; } + + private: + double _M_p; + }; + + + /** + * @brief A discrete geometric random number distribution. + * + * The formula for the geometric probability mass function is + * @f$ p(i) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the + * distribution. + */ + template<typename _IntType = int, typename _RealType = double> + class geometric_distribution + { + public: + // types + typedef _RealType input_type; + typedef _IntType result_type; + + // constructors and member function + explicit + geometric_distribution(const _RealType& __p = _RealType(0.5)) + : _M_p(__p) + { + _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0)); + _M_initialize(); + } + + /** + * Gets the distribution parameter @p p. + */ + _RealType + p() const + { return _M_p; } + + void + reset() { } + + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %geometric_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %geometric_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + 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<_IntType1, _RealType1>& __x); + + /** + * Extracts a %geometric_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %geometric_distribution random number generator engine. + * + * @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& __x) + { + __is >> __x._M_p; + __x._M_initialize(); + return __is; + } + + private: + void + _M_initialize() + { _M_log_p = std::log(_M_p); } + + _RealType _M_p; + _RealType _M_log_p; + }; + + + template<typename _RealType> + class normal_distribution; + + /** + * @brief A discrete Poisson random number distribution. + * + * The formula for the Poisson probability mass function is + * @f$ p(i) = \frac{mean^i}{i!} e^{-mean} @f$ where @f$ mean @f$ is the + * parameter of the distribution. + */ + template<typename _IntType = int, typename _RealType = double> + class poisson_distribution + { + public: + // types + typedef _RealType input_type; + typedef _IntType result_type; + + // constructors and member function + explicit + poisson_distribution(const _RealType& __mean = _RealType(1)) + : _M_mean(__mean), _M_nd() + { + _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0); + _M_initialize(); + } + + /** + * Gets the distribution parameter @p mean. + */ + _RealType + mean() const + { return _M_mean; } + + void + reset() + { _M_nd.reset(); } + + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %poisson_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %poisson_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType1, typename _RealType1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType1, _RealType1>& __x); + + /** + * Extracts a %poisson_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %poisson_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _IntType1, typename _RealType1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType1, _RealType1>& __x); + + private: + void + _M_initialize(); + + // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. + normal_distribution<_RealType> _M_nd; + + _RealType _M_mean; + + // Hosts either log(mean) or the threshold of the simple method. + _RealType _M_lm_thr; +#if _GLIBCXX_USE_C99_MATH_TR1 + _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb; +#endif + }; + + + /** + * @brief A discrete binomial random number distribution. + * + * The formula for the binomial probability mass function is + * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$ + * and @f$ p @f$ are the parameters of the distribution. + */ + template<typename _IntType = int, typename _RealType = double> + class binomial_distribution + { + public: + // types + typedef _RealType input_type; + typedef _IntType result_type; + + // constructors and member function + explicit + binomial_distribution(_IntType __t = 1, + const _RealType& __p = _RealType(0.5)) + : _M_t(__t), _M_p(__p), _M_nd() + { + _GLIBCXX_DEBUG_ASSERT((_M_t >= 0) && (_M_p >= 0.0) && (_M_p <= 1.0)); + _M_initialize(); + } + + /** + * Gets the distribution @p t parameter. + */ + _IntType + t() const + { return _M_t; } + + /** + * Gets the distribution @p p parameter. + */ + _RealType + p() const + { return _M_p; } + + void + reset() + { _M_nd.reset(); } + + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %binomial_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %binomial_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _IntType1, typename _RealType1, + typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType1, _RealType1>& __x); + + /** + * Extracts a %binomial_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %binomial_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _IntType1, typename _RealType1, + typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType1, _RealType1>& __x); + + private: + void + _M_initialize(); + + template<class _UniformRandomNumberGenerator> + result_type + _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t); + + // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. + normal_distribution<_RealType> _M_nd; + + _RealType _M_q; +#if _GLIBCXX_USE_C99_MATH_TR1 + _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c, + _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p; +#endif + _RealType _M_p; + _IntType _M_t; + + bool _M_easy; + }; + + /* @} */ // group tr1_random_distributions_discrete + + /** + * @addtogroup tr1_random_distributions_continuous Continuous Distributions + * @ingroup tr1_random_distributions + * @{ + */ + + /** + * @brief Uniform continuous distribution for random numbers. + * + * A continuous random distribution on the range [min, max) with equal + * probability throughout the range. The URNG should be real-valued and + * deliver number in the range [0, 1). + */ + template<typename _RealType = double> + class uniform_real + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs a uniform_real object. + * + * @param __min [IN] The lower bound of the distribution. + * @param __max [IN] The upper bound of the distribution. + */ + explicit + uniform_real(_RealType __min = _RealType(0), + _RealType __max = _RealType(1)) + : _M_min(__min), _M_max(__max) + { + _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); + } + + result_type + min() const + { return _M_min; } + + result_type + max() const + { return _M_max; } + + void + reset() { } + + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return (__urng() * (_M_max - _M_min)) + _M_min; } + + /** + * Inserts a %uniform_real random number distribution @p __x into the + * output stream @p __os. + * + * @param __os An output stream. + * @param __x A %uniform_real random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_real<_RealType1>& __x); + + /** + * Extracts a %uniform_real random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %uniform_real random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + uniform_real<_RealType1>& __x); + + private: + _RealType _M_min; + _RealType _M_max; + }; + + + /** + * @brief An exponential continuous distribution for random numbers. + * + * The formula for the exponential probability mass function is + * @f$ p(x) = \lambda e^{-\lambda x} @f$. + * + * <table border=1 cellpadding=10 cellspacing=0> + * <caption align=top>Distribution Statistics</caption> + * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr> + * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr> + * <tr><td>Mode</td><td>@f$ zero @f$</td></tr> + * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr> + * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr> + * </table> + */ + template<typename _RealType = double> + class exponential_distribution + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs an exponential distribution with inverse scale parameter + * @f$ \lambda @f$. + */ + explicit + exponential_distribution(const result_type& __lambda = result_type(1)) + : _M_lambda(__lambda) + { + _GLIBCXX_DEBUG_ASSERT(_M_lambda > 0); + } + + /** + * Gets the inverse scale parameter of the distribution. + */ + _RealType + lambda() const + { return _M_lambda; } + + /** + * Resets the distribution. + * + * Has no effect on exponential distributions. + */ + void + reset() { } + + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { return -std::log(__urng()) / _M_lambda; } + + /** + * Inserts a %exponential_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %exponential_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType1>& __x); + + /** + * Extracts a %exponential_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %exponential_distribution random number + * generator engine. + * + * @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& __x) + { return __is >> __x._M_lambda; } + + private: + result_type _M_lambda; + }; + + + /** + * @brief A normal continuous distribution for random numbers. + * + * The formula for the normal probability mass function is + * @f$ p(x) = \frac{1}{\sigma \sqrt{2 \pi}} + * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$. + */ + template<typename _RealType = double> + class normal_distribution + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs a normal distribution with parameters @f$ mean @f$ and + * @f$ \sigma @f$. + */ + explicit + normal_distribution(const result_type& __mean = result_type(0), + const result_type& __sigma = result_type(1)) + : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(false) + { + _GLIBCXX_DEBUG_ASSERT(_M_sigma > 0); + } + + /** + * Gets the mean of the distribution. + */ + _RealType + mean() const + { return _M_mean; } + + /** + * Gets the @f$ \sigma @f$ of the distribution. + */ + _RealType + sigma() const + { return _M_sigma; } + + /** + * Resets the distribution. + */ + void + reset() + { _M_saved_available = false; } + + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %normal_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %normal_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType1>& __x); + + /** + * Extracts a %normal_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %normal_distribution random number generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RealType1>& __x); + + private: + result_type _M_mean; + result_type _M_sigma; + result_type _M_saved; + bool _M_saved_available; + }; + + + /** + * @brief A gamma continuous distribution for random numbers. + * + * The formula for the gamma probability mass function is + * @f$ p(x) = \frac{1}{\Gamma(\alpha)} x^{\alpha - 1} e^{-x} @f$. + */ + template<typename _RealType = double> + class gamma_distribution + { + public: + // types + typedef _RealType input_type; + typedef _RealType result_type; + + public: + /** + * Constructs a gamma distribution with parameters @f$ \alpha @f$. + */ + explicit + gamma_distribution(const result_type& __alpha_val = result_type(1)) + : _M_alpha(__alpha_val) + { + _GLIBCXX_DEBUG_ASSERT(_M_alpha > 0); + _M_initialize(); + } + + /** + * Gets the @f$ \alpha @f$ of the distribution. + */ + _RealType + alpha() const + { return _M_alpha; } + + /** + * Resets the distribution. + */ + void + reset() { } + + template<class _UniformRandomNumberGenerator> + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + /** + * Inserts a %gamma_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %gamma_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template<typename _RealType1, typename _CharT, typename _Traits> + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RealType1>& __x); + + /** + * Extracts a %gamma_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %gamma_distribution random number generator engine. + * + * @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, + gamma_distribution& __x) + { + __is >> __x._M_alpha; + __x._M_initialize(); + return __is; + } + + private: + void + _M_initialize(); + + result_type _M_alpha; + + // Hosts either lambda of GB or d of modified Vaduva's. + result_type _M_l_d; + }; + + /* @} */ // group tr1_random_distributions_continuous + /* @} */ // group tr1_random_distributions + /* @} */ // group tr1_random + +} +} + +#include <tr1/random.tcc> + +#endif // _GLIBCXX_TR1_RANDOM_H diff --git a/libstdc++-v3/include/tr1/random.tcc b/libstdc++-v3/include/tr1/random.tcc new file mode 100644 index 00000000000..ec06ae31a6c --- /dev/null +++ b/libstdc++-v3/include/tr1/random.tcc @@ -0,0 +1,1583 @@ +// random number generation (out of line) -*- C++ -*- + +// Copyright (C) 2007 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +/** @file tr1/random.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +namespace std +{ +namespace tr1 +{ + + /* + * (Further) implementation-space details. + */ + namespace __detail + { + // General case for x = (ax + c) mod m -- use Schrage's algorithm to avoid + // integer overflow. + // + // Because a and c are compile-time integral constants the compiler kindly + // elides any unreachable paths. + // + // Preconditions: a > 0, m > 0. + // + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool> + struct _Mod + { + static _Tp + __calc(_Tp __x) + { + if (__a == 1) + __x %= __m; + else + { + static const _Tp __q = __m / __a; + static const _Tp __r = __m % __a; + + _Tp __t1 = __a * (__x % __q); + _Tp __t2 = __r * (__x / __q); + if (__t1 >= __t2) + __x = __t1 - __t2; + else + __x = __m - __t2 + __t1; + } + + if (__c != 0) + { + const _Tp __d = __m - __x; + if (__d > __c) + __x += __c; + else + __x = __c - __d; + } + return __x; + } + }; + + // Special case for m == 0 -- use unsigned integer overflow as modulo + // operator. + template<typename _Tp, _Tp __a, _Tp __c, _Tp __m> + struct _Mod<_Tp, __a, __c, __m, true> + { + static _Tp + __calc(_Tp __x) + { return __a * __x + __c; } + }; + } // namespace __detail + + /** + * Seeds the LCR with integral value @p __x0, adjusted so that the + * ring identity is never a member of the convergence set. + */ + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + void + linear_congruential<_UIntType, __a, __c, __m>:: + seed(unsigned long __x0) + { + if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) + && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); + else + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); + } + + /** + * Seeds the LCR engine with a value generated by @p __g. + */ + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + template<class _Gen> + void + linear_congruential<_UIntType, __a, __c, __m>:: + seed(_Gen& __g, false_type) + { + _UIntType __x0 = __g(); + if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) + && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); + else + _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); + } + + /** + * Gets the next generated value in sequence. + */ + template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + typename linear_congruential<_UIntType, __a, __c, __m>::result_type + linear_congruential<_UIntType, __a, __c, __m>:: + operator()() + { + _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x); + 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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + __os.flags(__ios_base::dec | __ios_base::fixed | __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__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, + _UIntType __b, int __t, _UIntType __c, int __l> + void + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>:: + seed(unsigned long __value) + { + _M_x[0] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__value); + + for (int __i = 1; __i < state_size; ++__i) + { + _UIntType __x = _M_x[__i - 1]; + __x ^= __x >> (__w - 2); + __x *= 1812433253ul; + __x += __i; + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__x); + } + _M_p = state_size; + } + + 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> + template<class _Gen> + void + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>:: + seed(_Gen& __gen, false_type) + { + for (int __i = 0; __i < state_size; ++__i) + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, + __detail::_Shift<_UIntType, __w>::__value>(__gen()); + _M_p = state_size; + } + + 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 + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>::result_type + mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, + __b, __t, __c, __l>:: + operator()() + { + // Reload the vector - cost is O(n) amortized over n calls. + if (_M_p >= state_size) + { + const _UIntType __upper_mask = (~_UIntType()) << __r; + const _UIntType __lower_mask = ~__upper_mask; + + for (int __k = 0; __k < (__n - __m); ++__k) + { + _UIntType __y = ((_M_x[__k] & __upper_mask) + | (_M_x[__k + 1] & __lower_mask)); + _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + } + + for (int __k = (__n - __m); __k < (__n - 1); ++__k) + { + _UIntType __y = ((_M_x[__k] & __upper_mask) + | (_M_x[__k + 1] & __lower_mask)); + _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + } + + _UIntType __y = ((_M_x[__n - 1] & __upper_mask) + | (_M_x[0] & __lower_mask)); + _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1) + ^ ((__y & 0x01) ? __a : 0)); + _M_p = 0; + } + + // Calculate o(x(i)). + result_type __z = _M_x[_M_p++]; + __z ^= (__z >> __u); + __z ^= (__z << __s) & __b; + __z ^= (__z << __t) & __c; + __z ^= (__z >> __l); + + 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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __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 + subtract_with_carry<_IntType, __m, __s, __r>:: + seed(unsigned long __value) + { + if (__value == 0) + __value = 19780503; + + std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563> + __lcg(__value); + + for (int __i = 0; __i < long_lag; ++__i) + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__lcg()); + + _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; + _M_p = 0; + } + + template<typename _IntType, _IntType __m, int __s, int __r> + template<class _Gen> + void + subtract_with_carry<_IntType, __m, __s, __r>:: + seed(_Gen& __gen, false_type) + { + const int __n = (std::numeric_limits<_UIntType>::digits + 31) / 32; + + for (int __i = 0; __i < long_lag; ++__i) + { + _UIntType __tmp = 0; + _UIntType __factor = 1; + for (int __j = 0; __j < __n; ++__j) + { + __tmp += __detail::__mod<__detail::_UInt32Type, 1, 0, 0> + (__gen()) * __factor; + __factor *= __detail::_Shift<_UIntType, 32>::__value; + } + _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__tmp); + } + _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; + _M_p = 0; + } + + template<typename _IntType, _IntType __m, int __s, int __r> + typename subtract_with_carry<_IntType, __m, __s, __r>::result_type + subtract_with_carry<_IntType, __m, __s, __r>:: + operator()() + { + // Derive short lag index from current index. + int __ps = _M_p - short_lag; + if (__ps < 0) + __ps += long_lag; + + // Calculate new x(i) without overflow or division. + // NB: Thanks to the requirements for _IntType, _M_x[_M_p] + _M_carry + // cannot overflow. + _UIntType __xi; + if (_M_x[__ps] >= _M_x[_M_p] + _M_carry) + { + __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry; + _M_carry = 0; + } + else + { + __xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps]; + _M_carry = 1; + } + _M_x[_M_p] = __xi; + + // Adjust current index to loop around in ring buffer. + if (++_M_p >= long_lag) + _M_p = 0; + + 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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __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) + { + typedef std::basic_ostream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __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<typename _RealType, int __w, int __s, int __r> + void + subtract_with_carry_01<_RealType, __w, __s, __r>:: + _M_initialize_npows() + { + for (int __j = 0; __j < __n; ++__j) +#if _GLIBCXX_USE_C99_MATH_TR1 + _M_npows[__j] = std::_GLIBCXX_TR1 ldexp(_RealType(1), -__w + __j * 32); +#else + _M_npows[__j] = std::pow(_RealType(2), -__w + __j * 32); +#endif + } + + template<typename _RealType, int __w, int __s, int __r> + void + subtract_with_carry_01<_RealType, __w, __s, __r>:: + seed(unsigned long __value) + { + if (__value == 0) + __value = 19780503; + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 512. Seeding subtract_with_carry_01 from a single unsigned long. + std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563> + __lcg(__value); + + this->seed(__lcg); + } + + template<typename _RealType, int __w, int __s, int __r> + template<class _Gen> + void + subtract_with_carry_01<_RealType, __w, __s, __r>:: + seed(_Gen& __gen, false_type) + { + for (int __i = 0; __i < long_lag; ++__i) + { + for (int __j = 0; __j < __n - 1; ++__j) + _M_x[__i][__j] = __detail::__mod<_UInt32Type, 1, 0, 0>(__gen()); + _M_x[__i][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, + __detail::_Shift<_UInt32Type, __w % 32>::__value>(__gen()); + } + + _M_carry = 1; + for (int __j = 0; __j < __n; ++__j) + if (_M_x[long_lag - 1][__j] != 0) + { + _M_carry = 0; + break; + } + + _M_p = 0; + } + + template<typename _RealType, int __w, int __s, int __r> + typename subtract_with_carry_01<_RealType, __w, __s, __r>::result_type + subtract_with_carry_01<_RealType, __w, __s, __r>:: + operator()() + { + // Derive short lag index from current index. + int __ps = _M_p - short_lag; + if (__ps < 0) + __ps += long_lag; + + _UInt32Type __new_carry; + for (int __j = 0; __j < __n - 1; ++__j) + { + if (_M_x[__ps][__j] > _M_x[_M_p][__j] + || (_M_x[__ps][__j] == _M_x[_M_p][__j] && _M_carry == 0)) + __new_carry = 0; + else + __new_carry = 1; + + _M_x[_M_p][__j] = _M_x[__ps][__j] - _M_x[_M_p][__j] - _M_carry; + _M_carry = __new_carry; + } + + if (_M_x[__ps][__n - 1] > _M_x[_M_p][__n - 1] + || (_M_x[__ps][__n - 1] == _M_x[_M_p][__n - 1] && _M_carry == 0)) + __new_carry = 0; + else + __new_carry = 1; + + _M_x[_M_p][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, + __detail::_Shift<_UInt32Type, __w % 32>::__value> + (_M_x[__ps][__n - 1] - _M_x[_M_p][__n - 1] - _M_carry); + _M_carry = __new_carry; + + result_type __ret = 0.0; + for (int __j = 0; __j < __n; ++__j) + __ret += _M_x[_M_p][__j] * _M_npows[__j]; + + // Adjust current index to loop around in ring buffer. + if (++_M_p >= long_lag) + _M_p = 0; + + return __ret; + } + + template<typename _RealType, int __w, int __s, int __r, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_01<_RealType, __w, __s, __r>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); + __os.fill(__space); + + for (int __i = 0; __i < __r; ++__i) + for (int __j = 0; __j < __x.__n; ++__j) + __os << __x._M_x[__i][__j] << __space; + __os << __x._M_carry; + + __os.flags(__flags); + __os.fill(__fill); + return __os; + } + + template<typename _RealType, int __w, int __s, int __r, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_01<_RealType, __w, __s, __r>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + for (int __i = 0; __i < __r; ++__i) + for (int __j = 0; __j < __x.__n; ++__j) + __is >> __x._M_x[__i][__j]; + __is >> __x._M_carry; + + __is.flags(__flags); + return __is; + } + + + template<class _UniformRandomNumberGenerator, int __p, int __r> + typename discard_block<_UniformRandomNumberGenerator, + __p, __r>::result_type + discard_block<_UniformRandomNumberGenerator, __p, __r>:: + operator()() + { + if (_M_n >= used_block) + { + while (_M_n < block_size) + { + _M_b(); + ++_M_n; + } + _M_n = 0; + } + ++_M_n; + 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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed + | __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_b >> __x._M_n; + + __is.flags(__flags); + return __is; + } + + + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2> + void + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>:: + _M_initialize_max() + { + const int __w = std::numeric_limits<result_type>::digits; + + const result_type __m1 = + std::min(result_type(_M_b1.max() - _M_b1.min()), + __detail::_Shift<result_type, __w - __s1>::__value - 1); + + const result_type __m2 = + std::min(result_type(_M_b2.max() - _M_b2.min()), + __detail::_Shift<result_type, __w - __s2>::__value - 1); + + // NB: In TR1 s1 is not required to be >= s2. + if (__s1 < __s2) + _M_max = _M_initialize_max_aux(__m2, __m1, __s2 - __s1) << __s1; + else + _M_max = _M_initialize_max_aux(__m1, __m2, __s1 - __s2) << __s2; + } + + template<class _UniformRandomNumberGenerator1, int __s1, + class _UniformRandomNumberGenerator2, int __s2> + typename xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>::result_type + xor_combine<_UniformRandomNumberGenerator1, __s1, + _UniformRandomNumberGenerator2, __s2>:: + _M_initialize_max_aux(result_type __a, result_type __b, int __d) + { + const result_type __two2d = result_type(1) << __d; + const result_type __c = __a * __two2d; + + if (__a == 0 || __b < __two2d) + return __c + __b; + + const result_type __t = std::max(__c, __b); + const result_type __u = std::min(__c, __b); + + result_type __ub = __u; + result_type __p; + for (__p = 0; __ub != 1; __ub >>= 1) + ++__p; + + const result_type __two2p = result_type(1) << __p; + const result_type __k = __t / __two2p; + + if (__k & 1) + return (__k + 1) * __two2p - 1; + + if (__c >= __b) + return (__k + 1) * __two2p + _M_initialize_max_aux((__t % __two2p) + / __two2d, + __u % __two2p, __d); + else + return (__k + 1) * __two2p + _M_initialize_max_aux((__u % __two2p) + / __two2d, + __t % __two2p, __d); + } + + 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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::dec | __ios_base::fixed | __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + __is >> __x._M_b1 >> __x._M_b2; + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType> + template<typename _UniformRandomNumberGenerator> + typename uniform_int<_IntType>::result_type + uniform_int<_IntType>:: + _M_call(_UniformRandomNumberGenerator& __urng, + result_type __min, result_type __max, true_type) + { + // XXX Must be fixed to work well for *arbitrary* __urng.max(), + // __urng.min(), __max, __min. Currently works fine only in the + // most common case __urng.max() - __urng.min() >= __max - __min, + // with __urng.max() > __urng.min() >= 0. + typedef typename __gnu_cxx::__add_unsigned<typename + _UniformRandomNumberGenerator::result_type>::__type __urntype; + typedef typename __gnu_cxx::__add_unsigned<result_type>::__type + __utype; + typedef typename __gnu_cxx::__conditional_type<(sizeof(__urntype) + > sizeof(__utype)), + __urntype, __utype>::__type __uctype; + + result_type __ret; + + const __urntype __urnmin = __urng.min(); + const __urntype __urnmax = __urng.max(); + const __urntype __urnrange = __urnmax - __urnmin; + const __uctype __urange = __max - __min; + const __uctype __udenom = (__urnrange <= __urange + ? 1 : __urnrange / (__urange + 1)); + do + __ret = (__urntype(__urng()) - __urnmin) / __udenom; + while (__ret > __max - __min); + + return __ret + __min; + } + + template<typename _IntType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const uniform_int<_IntType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits<double>::__max_digits10); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template<typename _IntType, typename _RealType> + template<class _UniformRandomNumberGenerator> + typename geometric_distribution<_IntType, _RealType>::result_type + geometric_distribution<_IntType, _RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + // About the epsilon thing see this thread: + // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html + const _RealType __naf = + (1 - std::numeric_limits<_RealType>::epsilon()) / 2; + // The largest _RealType convertible to _IntType. + const _RealType __thr = + std::numeric_limits<_IntType>::max() + __naf; + + _RealType __cand; + do + __cand = std::ceil(std::log(__urng()) / _M_log_p); + while (__cand >= __thr); + + return result_type(__cand + __naf); + } + + 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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.p(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + template<typename _IntType, typename _RealType> + void + poisson_distribution<_IntType, _RealType>:: + _M_initialize() + { +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_mean >= 12) + { + const _RealType __m = std::floor(_M_mean); + _M_lm_thr = std::log(_M_mean); + _M_lfm = std::_GLIBCXX_TR1 lgamma(__m + 1); + _M_sm = std::sqrt(__m); + + const _RealType __pi_4 = 0.7853981633974483096156608458198757L; + const _RealType __dx = std::sqrt(2 * __m * std::log(32 * __m + / __pi_4)); + _M_d = std::_GLIBCXX_TR1 round(std::max(_RealType(6), + std::min(__m, __dx))); + const _RealType __cx = 2 * __m + _M_d; + _M_scx = std::sqrt(__cx / 2); + _M_1cx = 1 / __cx; + + _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx); + _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2)) / _M_d; + } + else +#endif + _M_lm_thr = std::exp(-_M_mean); + } + + /** + * A rejection algorithm when mean >= 12 and a simple method based + * upon the multiplication of uniform random variates otherwise. + * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 + * is defined. + * + * Reference: + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!). + */ + template<typename _IntType, typename _RealType> + template<class _UniformRandomNumberGenerator> + typename poisson_distribution<_IntType, _RealType>::result_type + poisson_distribution<_IntType, _RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_mean >= 12) + { + _RealType __x; + + // See comments above... + const _RealType __naf = + (1 - std::numeric_limits<_RealType>::epsilon()) / 2; + const _RealType __thr = + std::numeric_limits<_IntType>::max() + __naf; + + const _RealType __m = std::floor(_M_mean); + // sqrt(pi / 2) + const _RealType __spi_2 = 1.2533141373155002512078826424055226L; + const _RealType __c1 = _M_sm * __spi_2; + const _RealType __c2 = _M_c2b + __c1; + const _RealType __c3 = __c2 + 1; + const _RealType __c4 = __c3 + 1; + // e^(1 / 78) + const _RealType __e178 = 1.0129030479320018583185514777512983L; + const _RealType __c5 = __c4 + __e178; + const _RealType __c = _M_cb + __c5; + const _RealType __2cx = 2 * (2 * __m + _M_d); + + bool __reject = true; + do + { + const _RealType __u = __c * __urng(); + const _RealType __e = -std::log(__urng()); + + _RealType __w = 0.0; + + if (__u <= __c1) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = -std::abs(__n) * _M_sm - 1; + __x = std::floor(__y); + __w = -__n * __n / 2; + if (__x < -__m) + continue; + } + else if (__u <= __c2) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = 1 + std::abs(__n) * _M_scx; + __x = std::ceil(__y); + __w = __y * (2 - __y) * _M_1cx; + if (__x > _M_d) + continue; + } + else if (__u <= __c3) + // NB: This case not in the book, nor in the Errata, + // but should be ok... + __x = -1; + else if (__u <= __c4) + __x = 0; + else if (__u <= __c5) + __x = 1; + else + { + const _RealType __v = -std::log(__urng()); + const _RealType __y = _M_d + __v * __2cx / _M_d; + __x = std::ceil(__y); + __w = -_M_d * _M_1cx * (1 + __y / 2); + } + + __reject = (__w - __e - __x * _M_lm_thr + > _M_lfm - std::_GLIBCXX_TR1 lgamma(__x + __m + 1)); + + __reject |= __x + __m >= __thr; + + } while (__reject); + + return result_type(__x + __m + __naf); + } + else +#endif + { + _IntType __x = 0; + _RealType __prod = 1.0; + + do + { + __prod *= __urng(); + __x += 1; + } + while (__prod > _M_lm_thr); + + return __x - 1; + } + } + + template<typename _IntType, typename _RealType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.mean() << __space << __x._M_nd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _IntType, typename _RealType, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::skipws); + + __is >> __x._M_mean >> __x._M_nd; + __x._M_initialize(); + + __is.flags(__flags); + return __is; + } + + + template<typename _IntType, typename _RealType> + void + binomial_distribution<_IntType, _RealType>:: + _M_initialize() + { + const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; + + _M_easy = true; + +#if _GLIBCXX_USE_C99_MATH_TR1 + if (_M_t * __p12 >= 8) + { + _M_easy = false; + const _RealType __np = std::floor(_M_t * __p12); + const _RealType __pa = __np / _M_t; + const _RealType __1p = 1 - __pa; + + const _RealType __pi_4 = 0.7853981633974483096156608458198757L; + const _RealType __d1x = + std::sqrt(__np * __1p * std::log(32 * __np + / (81 * __pi_4 * __1p))); + _M_d1 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d1x)); + const _RealType __d2x = + std::sqrt(__np * __1p * std::log(32 * _M_t * __1p + / (__pi_4 * __pa))); + _M_d2 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d2x)); + + // sqrt(pi / 2) + const _RealType __spi_2 = 1.2533141373155002512078826424055226L; + _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np)); + _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p)); + _M_c = 2 * _M_d1 / __np; + _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2; + const _RealType __a12 = _M_a1 + _M_s2 * __spi_2; + const _RealType __s1s = _M_s1 * _M_s1; + _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p)) + * 2 * __s1s / _M_d1 + * std::exp(-_M_d1 * _M_d1 / (2 * __s1s))); + const _RealType __s2s = _M_s2 * _M_s2; + _M_s = (_M_a123 + 2 * __s2s / _M_d2 + * std::exp(-_M_d2 * _M_d2 / (2 * __s2s))); + _M_lf = (std::_GLIBCXX_TR1 lgamma(__np + 1) + + std::_GLIBCXX_TR1 lgamma(_M_t - __np + 1)); + _M_lp1p = std::log(__pa / __1p); + + _M_q = -std::log(1 - (__p12 - __pa) / __1p); + } + else +#endif + _M_q = -std::log(1 - __p12); + } + + template<typename _IntType, typename _RealType> + template<class _UniformRandomNumberGenerator> + typename binomial_distribution<_IntType, _RealType>::result_type + binomial_distribution<_IntType, _RealType>:: + _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t) + { + _IntType __x = 0; + _RealType __sum = 0; + + do + { + const _RealType __e = -std::log(__urng()); + __sum += __e / (__t - __x); + __x += 1; + } + while (__sum <= _M_q); + + return __x - 1; + } + + /** + * A rejection algorithm when t * p >= 8 and a simple waiting time + * method - the second in the referenced book - otherwise. + * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 + * is defined. + * + * Reference: + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. X, Sect. 4 (+ Errata!). + */ + template<typename _IntType, typename _RealType> + template<class _UniformRandomNumberGenerator> + typename binomial_distribution<_IntType, _RealType>::result_type + binomial_distribution<_IntType, _RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __ret; + const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; + +#if _GLIBCXX_USE_C99_MATH_TR1 + if (!_M_easy) + { + _RealType __x; + + // See comments above... + const _RealType __naf = + (1 - std::numeric_limits<_RealType>::epsilon()) / 2; + const _RealType __thr = + std::numeric_limits<_IntType>::max() + __naf; + + const _RealType __np = std::floor(_M_t * __p12); + const _RealType __pa = __np / _M_t; + + // sqrt(pi / 2) + const _RealType __spi_2 = 1.2533141373155002512078826424055226L; + const _RealType __a1 = _M_a1; + const _RealType __a12 = __a1 + _M_s2 * __spi_2; + const _RealType __a123 = _M_a123; + const _RealType __s1s = _M_s1 * _M_s1; + const _RealType __s2s = _M_s2 * _M_s2; + + bool __reject; + do + { + const _RealType __u = _M_s * __urng(); + + _RealType __v; + + if (__u <= __a1) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = _M_s1 * std::abs(__n); + __reject = __y >= _M_d1; + if (!__reject) + { + const _RealType __e = -std::log(__urng()); + __x = std::floor(__y); + __v = -__e - __n * __n / 2 + _M_c; + } + } + else if (__u <= __a12) + { + const _RealType __n = _M_nd(__urng); + const _RealType __y = _M_s2 * std::abs(__n); + __reject = __y >= _M_d2; + if (!__reject) + { + const _RealType __e = -std::log(__urng()); + __x = std::floor(-__y); + __v = -__e - __n * __n / 2; + } + } + else if (__u <= __a123) + { + const _RealType __e1 = -std::log(__urng()); + const _RealType __e2 = -std::log(__urng()); + + const _RealType __y = _M_d1 + 2 * __s1s * __e1 / _M_d1; + __x = std::floor(__y); + __v = (-__e2 + _M_d1 * (1 / (_M_t - __np) + -__y / (2 * __s1s))); + __reject = false; + } + else + { + const _RealType __e1 = -std::log(__urng()); + const _RealType __e2 = -std::log(__urng()); + + const _RealType __y = _M_d2 + 2 * __s2s * __e1 / _M_d2; + __x = std::floor(-__y); + __v = -__e2 - _M_d2 * __y / (2 * __s2s); + __reject = false; + } + + __reject = __reject || __x < -__np || __x > _M_t - __np; + if (!__reject) + { + const _RealType __lfx = + std::_GLIBCXX_TR1 lgamma(__np + __x + 1) + + std::_GLIBCXX_TR1 lgamma(_M_t - (__np + __x) + 1); + __reject = __v > _M_lf - __lfx + __x * _M_lp1p; + } + + __reject |= __x + __np >= __thr; + } + while (__reject); + + __x += __np + __naf; + + const _IntType __z = _M_waiting(__urng, _M_t - _IntType(__x)); + __ret = _IntType(__x) + __z; + } + else +#endif + __ret = _M_waiting(__urng, _M_t); + + if (__p12 != _M_p) + __ret = _M_t - __ret; + return __ret; + } + + template<typename _IntType, typename _RealType, + typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.t() << __space << __x.p() + << __space << __x._M_nd; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template<typename _IntType, typename _RealType, + typename _CharT, typename _Traits> + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType, _RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_t >> __x._M_p >> __x._M_nd; + __x._M_initialize(); + + __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 uniform_real<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__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) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.lambda(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + + /** + * Polar method due to Marsaglia. + * + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. V, Sect. 4.4. + */ + template<typename _RealType> + template<class _UniformRandomNumberGenerator> + typename normal_distribution<_RealType>::result_type + normal_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __ret; + + if (_M_saved_available) + { + _M_saved_available = false; + __ret = _M_saved; + } + else + { + result_type __x, __y, __r2; + do + { + __x = result_type(2.0) * __urng() - 1.0; + __y = result_type(2.0) * __urng() - 1.0; + __r2 = __x * __x + __y * __y; + } + while (__r2 > 1.0 || __r2 == 0.0); + + const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2); + _M_saved = __x * __mult; + _M_saved_available = true; + __ret = __y * __mult; + } + + __ret = __ret * _M_sigma + _M_mean; + return __ret; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x._M_saved_available << __space + << __x.mean() << __space + << __x.sigma(); + if (__x._M_saved_available) + __os << __space << __x._M_saved; + + __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) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + __is >> __x._M_saved_available >> __x._M_mean + >> __x._M_sigma; + if (__x._M_saved_available) + __is >> __x._M_saved; + + __is.flags(__flags); + return __is; + } + + + template<typename _RealType> + void + gamma_distribution<_RealType>:: + _M_initialize() + { + if (_M_alpha >= 1) + _M_l_d = std::sqrt(2 * _M_alpha - 1); + else + _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha)) + * (1 - _M_alpha)); + } + + /** + * Cheng's rejection algorithm GB for alpha >= 1 and a modification + * of Vaduva's rejection from Weibull algorithm due to Devroye for + * alpha < 1. + * + * References: + * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral + * Shape Parameter." Applied Statistics, 26, 71-75, 1977. + * + * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection + * and Composition Procedures." Math. Operationsforschung and Statistik, + * Series in Statistics, 8, 545-576, 1977. + * + * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, + * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!). + */ + template<typename _RealType> + template<class _UniformRandomNumberGenerator> + typename gamma_distribution<_RealType>::result_type + gamma_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x; + + bool __reject; + if (_M_alpha >= 1) + { + // alpha - log(4) + const result_type __b = _M_alpha + - result_type(1.3862943611198906188344642429163531L); + const result_type __c = _M_alpha + _M_l_d; + const result_type __1l = 1 / _M_l_d; + + // 1 + log(9 / 2) + const result_type __k = 2.5040773967762740733732583523868748L; + + do + { + const result_type __u = __urng(); + const result_type __v = __urng(); + + const result_type __y = __1l * std::log(__v / (1 - __v)); + __x = _M_alpha * std::exp(__y); + + const result_type __z = __u * __v * __v; + const result_type __r = __b + __c * __y - __x; + + __reject = __r < result_type(4.5) * __z - __k; + if (__reject) + __reject = __r < std::log(__z); + } + while (__reject); + } + else + { + const result_type __c = 1 / _M_alpha; + + do + { + const result_type __z = -std::log(__urng()); + const result_type __e = -std::log(__urng()); + + __x = std::pow(__z, __c); + + __reject = __z + __e < _M_l_d + __x; + } + while (__reject); + } + + return __x; + } + + template<typename _RealType, typename _CharT, typename _Traits> + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__os.widen(' ')); + __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); + + __os << __x.alpha(); + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + +} +} diff --git a/libstdc++-v3/include/tr1_impl/random b/libstdc++-v3/include/tr1_impl/random index 49ac5980854..e69de29bb2d 100644 --- a/libstdc++-v3/include/tr1_impl/random +++ b/libstdc++-v3/include/tr1_impl/random @@ -1,2412 +0,0 @@ -// random number generation -*- C++ -*- - -// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/** - * @file tr1_impl/random - * This is an internal header file, included by other library headers. - * You should not attempt to use it directly. - */ - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE_TR1 - - // [5.1] Random number generation - - /** - * @defgroup tr1_random Random Number Generation - * @ingroup numerics - * A facility for generating random numbers on selected distributions. - * @{ - */ - - /* - * Implementation-space details. - */ - namespace __detail - { - template<typename _UIntType, int __w, - bool = __w < std::numeric_limits<_UIntType>::digits> - struct _Shift - { static const _UIntType __value = 0; }; - - template<typename _UIntType, int __w> - struct _Shift<_UIntType, __w, true> - { static const _UIntType __value = _UIntType(1) << __w; }; - - template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool> - struct _Mod; - - // Dispatch based on modulus value to prevent divide-by-zero compile-time - // errors when m == 0. - template<typename _Tp, _Tp __a, _Tp __c, _Tp __m> - inline _Tp - __mod(_Tp __x) - { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); } - - typedef __gnu_cxx::__conditional_type<(sizeof(unsigned) == 4), - unsigned, unsigned long>::__type _UInt32Type; - - /* - * An adaptor class for converting the output of any Generator into - * the input for a specific Distribution. - */ - template<typename _Engine, typename _Distribution> - struct _Adaptor - { - typedef typename remove_reference<_Engine>::type _BEngine; - typedef typename _BEngine::result_type _Engine_result_type; - typedef typename _Distribution::input_type result_type; - - public: - _Adaptor(const _Engine& __g) - : _M_g(__g) { } - - result_type - min() const - { - result_type __return_value; - if (is_integral<_Engine_result_type>::value - && is_integral<result_type>::value) - __return_value = _M_g.min(); - else - __return_value = result_type(0); - return __return_value; - } - - result_type - max() const - { - result_type __return_value; - if (is_integral<_Engine_result_type>::value - && is_integral<result_type>::value) - __return_value = _M_g.max(); - else if (!is_integral<result_type>::value) - __return_value = result_type(1); - else - __return_value = std::numeric_limits<result_type>::max() - 1; - return __return_value; - } - - /* - * Converts a value generated by the adapted random number generator - * into a value in the input domain for the dependent random number - * distribution. - * - * Because the type traits are compile time constants only the - * appropriate clause of the if statements will actually be emitted - * by the compiler. - */ - result_type - operator()() - { - result_type __return_value; - if (is_integral<_Engine_result_type>::value - && is_integral<result_type>::value) - __return_value = _M_g(); - else if (!is_integral<_Engine_result_type>::value - && !is_integral<result_type>::value) - __return_value = result_type(_M_g() - _M_g.min()) - / result_type(_M_g.max() - _M_g.min()); - else if (is_integral<_Engine_result_type>::value - && !is_integral<result_type>::value) - __return_value = result_type(_M_g() - _M_g.min()) - / result_type(_M_g.max() - _M_g.min() + result_type(1)); - else - __return_value = (((_M_g() - _M_g.min()) - / (_M_g.max() - _M_g.min())) - * std::numeric_limits<result_type>::max()); - return __return_value; - } - - private: - _Engine _M_g; - }; - - // Specialization for _Engine*. - template<typename _Engine, typename _Distribution> - struct _Adaptor<_Engine*, _Distribution> - { - typedef typename _Engine::result_type _Engine_result_type; - typedef typename _Distribution::input_type result_type; - - public: - _Adaptor(_Engine* __g) - : _M_g(__g) { } - - result_type - min() const - { - result_type __return_value; - if (is_integral<_Engine_result_type>::value - && is_integral<result_type>::value) - __return_value = _M_g->min(); - else - __return_value = result_type(0); - return __return_value; - } - - result_type - max() const - { - result_type __return_value; - if (is_integral<_Engine_result_type>::value - && is_integral<result_type>::value) - __return_value = _M_g->max(); - else if (!is_integral<result_type>::value) - __return_value = result_type(1); - else - __return_value = std::numeric_limits<result_type>::max() - 1; - return __return_value; - } - - result_type - operator()() - { - result_type __return_value; - if (is_integral<_Engine_result_type>::value - && is_integral<result_type>::value) - __return_value = (*_M_g)(); - else if (!is_integral<_Engine_result_type>::value - && !is_integral<result_type>::value) - __return_value = result_type((*_M_g)() - _M_g->min()) - / result_type(_M_g->max() - _M_g->min()); - else if (is_integral<_Engine_result_type>::value - && !is_integral<result_type>::value) - __return_value = result_type((*_M_g)() - _M_g->min()) - / result_type(_M_g->max() - _M_g->min() + result_type(1)); - else - __return_value = ((((*_M_g)() - _M_g->min()) - / (_M_g->max() - _M_g->min())) - * std::numeric_limits<result_type>::max()); - return __return_value; - } - - private: - _Engine* _M_g; - }; - } // namespace __detail - - /** - * Produces random numbers on a given distribution function using a - * non-uniform random number generation engine. - * - * @todo the engine_value_type needs to be studied more carefully. - */ - template<typename _Engine, typename _Dist> - class variate_generator - { - // Concept requirements. - __glibcxx_class_requires(_Engine, _CopyConstructibleConcept) - // __glibcxx_class_requires(_Engine, _EngineConcept) - // __glibcxx_class_requires(_Dist, _EngineConcept) - - public: - typedef _Engine engine_type; - typedef __detail::_Adaptor<_Engine, _Dist> engine_value_type; - typedef _Dist distribution_type; - typedef typename _Dist::result_type result_type; - - // tr1:5.1.1 table 5.1 requirement - typedef typename __gnu_cxx::__enable_if< - is_arithmetic<result_type>::value, result_type>::__type _IsValidType; - - /** - * Constructs a variate generator with the uniform random number - * generator @p __eng for the random distribution @p __dist. - * - * @throws Any exceptions which may thrown by the copy constructors of - * the @p _Engine or @p _Dist objects. - */ - variate_generator(engine_type __eng, distribution_type __dist) - : _M_engine(__eng), _M_dist(__dist) { } - - /** - * Gets the next generated value on the distribution. - */ - result_type - operator()() - { return _M_dist(_M_engine); } - - /** - * WTF? - */ - template<typename _Tp> - result_type - operator()(_Tp __value) - { return _M_dist(_M_engine, __value); } - - /** - * Gets a reference to the underlying uniform random number generator - * object. - */ - engine_value_type& - engine() - { return _M_engine; } - - /** - * Gets a const reference to the underlying uniform random number - * generator object. - */ - const engine_value_type& - engine() const - { return _M_engine; } - - /** - * Gets a reference to the underlying random distribution. - */ - distribution_type& - distribution() - { return _M_dist; } - - /** - * Gets a const reference to the underlying random distribution. - */ - const distribution_type& - distribution() const - { return _M_dist; } - - /** - * Gets the closed lower bound of the distribution interval. - */ - result_type - min() const - { return this->distribution().min(); } - - /** - * Gets the closed upper bound of the distribution interval. - */ - result_type - max() const - { return this->distribution().max(); } - - private: - engine_value_type _M_engine; - distribution_type _M_dist; - }; - - - /** - * @defgroup tr1_random_generators Random Number Generators - * @ingroup tr1_random - * - * These classes define objects which provide random or pseudorandom - * numbers, either from a discrete or a continuous interval. The - * random number generator supplied as a part of this library are - * all uniform random number generators which provide a sequence of - * random number uniformly distributed over their range. - * - * A number generator is a function object with an operator() that - * takes zero arguments and returns a number. - * - * A compliant random number generator must satisfy the following - * requirements. <table border=1 cellpadding=10 cellspacing=0> - * <caption align=top>Random Number Generator Requirements</caption> - * <tr><td>To be documented.</td></tr> </table> - * - * @{ - */ - - /** - * @brief A model of a linear congruential random number generator. - * - * A random number generator that produces pseudorandom numbers using the - * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$. - * - * The template parameter @p _UIntType must be an unsigned integral type - * large enough to store values up to (__m-1). If the template parameter - * @p __m is 0, the modulus @p __m used is - * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template - * parameters @p __a and @p __c must be less than @p __m. - * - * The size of the state is @f$ 1 @f$. - */ - template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> - class linear_congruential - { - __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) - // __glibcpp_class_requires(__a < __m && __c < __m) - - public: - /** The type of the generated random value. */ - typedef _UIntType result_type; - - /** The multiplier. */ - static const _UIntType multiplier = __a; - /** An increment. */ - static const _UIntType increment = __c; - /** The modulus. */ - static const _UIntType modulus = __m; - - /** - * Constructs a %linear_congruential random number generator engine with - * seed @p __s. The default seed value is 1. - * - * @param __s The initial seed value. - */ - explicit - linear_congruential(unsigned long __x0 = 1) - { this->seed(__x0); } - - /** - * Constructs a %linear_congruential random number generator engine - * seeded from the generator function @p __g. - * - * @param __g The seed generator function. - */ - template<class _Gen> - linear_congruential(_Gen& __g) - { this->seed(__g); } - - /** - * Reseeds the %linear_congruential random number generator engine - * sequence to the seed @g __s. - * - * @param __s The new seed. - */ - void - seed(unsigned long __s = 1); - - /** - * Reseeds the %linear_congruential random number generator engine - * sequence using values from the generator function @p __g. - * - * @param __g the seed generator function. - */ - template<class _Gen> - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - /** - * Gets the smallest possible value in the output range. - * - * The minimum depends on the @p __c parameter: if it is zero, the - * minimum generated must be > 0, otherwise 0 is allowed. - */ - result_type - min() const - { return (__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; } - - /** - * Gets the largest possible value in the output range. - */ - result_type - max() const - { return __m - 1; } - - /** - * Gets the next random number in the sequence. - */ - result_type - operator()(); - - /** - * Compares two linear congruential random number generator - * objects of the same type for equality. - * - * @param __lhs A linear congruential random number generator object. - * @param __rhs Another linear congruential random number generator obj. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const linear_congruential& __lhs, - const linear_congruential& __rhs) - { return __lhs._M_x == __rhs._M_x; } - - /** - * Compares two linear congruential random number generator - * objects of the same type for inequality. - * - * @param __lhs A linear congruential random number generator object. - * @param __rhs Another linear congruential random number generator obj. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const linear_congruential& __lhs, - const linear_congruential& __rhs) - { return !(__lhs == __rhs); } - - /** - * 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. - * @returns __os. - */ - 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<_UIntType1, __a1, __c1, - __m1>& __lcr); - - /** - * Sets the state of the engine by reading its textual - * representation from @p __is. - * - * The textual representation must have been previously written using an - * output stream whose imbued locale and whose type's template - * specialization arguments _CharT and _Traits were the same as those of - * @p __is. - * - * @param __is The input stream. - * @param __lcr A % linear_congruential random number generator. - * @returns __is. - */ - 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<_UIntType1, __a1, __c1, __m1>& __lcr); - - private: - template<class _Gen> - void - seed(_Gen& __g, true_type) - { return seed(static_cast<unsigned long>(__g)); } - - template<class _Gen> - void - seed(_Gen& __g, false_type); - - _UIntType _M_x; - }; - - /** - * The classic Minimum Standard rand0 of Lewis, Goodman, and Miller. - */ - typedef linear_congruential<unsigned long, 16807, 0, 2147483647> minstd_rand0; - - /** - * An alternative LCR (Lehmer Generator function) . - */ - typedef linear_congruential<unsigned long, 48271, 0, 2147483647> minstd_rand; - - - /** - * A generalized feedback shift register discrete random number generator. - * - * This algorithm avoids multiplication and division and is designed to be - * friendly to a pipelined architecture. If the parameters are chosen - * correctly, this generator will produce numbers with a very long period and - * fairly good apparent entropy, although still not cryptographically strong. - * - * The best way to use this generator is with the predefined mt19937 class. - * - * This algorithm was originally invented by Makoto Matsumoto and - * Takuji Nishimura. - * - * @var word_size The number of bits in each element of the state vector. - * @var state_size The degree of recursion. - * @var shift_size The period parameter. - * @var mask_bits The separation point bit index. - * @var parameter_a The last row of the twist matrix. - * @var output_u The first right-shift tempering matrix parameter. - * @var output_s The first left-shift tempering matrix parameter. - * @var output_b The first left-shift tempering matrix mask. - * @var output_t The second left-shift tempering matrix parameter. - * @var output_c The second left-shift tempering matrix mask. - * @var output_l The second right-shift tempering matrix parameter. - */ - 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) - - public: - // types - typedef _UIntType result_type; - - // parameter values - static const int word_size = __w; - static const int state_size = __n; - static const int shift_size = __m; - static const int mask_bits = __r; - static const _UIntType parameter_a = __a; - static const int output_u = __u; - static const int output_s = __s; - static const _UIntType output_b = __b; - static const int output_t = __t; - static const _UIntType output_c = __c; - static const int output_l = __l; - - // constructors and member function - mersenne_twister() - { seed(); } - - explicit - mersenne_twister(unsigned long __value) - { seed(__value); } - - template<class _Gen> - mersenne_twister(_Gen& __g) - { seed(__g); } - - void - seed() - { seed(5489UL); } - - void - seed(unsigned long __value); - - template<class _Gen> - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - result_type - min() const - { return 0; }; - - result_type - max() const - { return __detail::_Shift<_UIntType, __w>::__value - 1; } - - result_type - operator()(); - - /** - * Compares two % mersenne_twister random number generator objects of - * the same type for equality. - * - * @param __lhs A % mersenne_twister random number generator object. - * @param __rhs Another % mersenne_twister random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const mersenne_twister& __lhs, - const mersenne_twister& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); } - - /** - * Compares two % mersenne_twister random number generator objects of - * the same type for inequality. - * - * @param __lhs A % mersenne_twister random number generator object. - * @param __rhs Another % mersenne_twister random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const mersenne_twister& __lhs, - const mersenne_twister& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a % mersenne_twister random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A % mersenne_twister random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - 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<_UIntType1, __w1, __n1, __m1, __r1, - __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); - - /** - * Extracts the current state of a % mersenne_twister random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A % mersenne_twister random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - 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<_UIntType1, __w1, __n1, __m1, __r1, - __a1, __u1, __s1, __b1, __t1, __c1, __l1>& __x); - - private: - template<class _Gen> - void - seed(_Gen& __g, true_type) - { return seed(static_cast<unsigned long>(__g)); } - - template<class _Gen> - void - seed(_Gen& __g, false_type); - - _UIntType _M_x[state_size]; - int _M_p; - }; - - /** - * The classic Mersenne Twister. - * - * Reference: - * M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally - * Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions - * on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. - */ - typedef mersenne_twister< - unsigned long, 32, 624, 397, 31, - 0x9908b0dful, 11, 7, - 0x9d2c5680ul, 15, - 0xefc60000ul, 18 - > mt19937; - - - /** - * @brief The Marsaglia-Zaman generator. - * - * This is a model of a Generalized Fibonacci discrete random number - * generator, sometimes referred to as the SWC generator. - * - * A discrete random number generator that produces pseudorandom - * numbers using @f$x_{i}\leftarrow(x_{i - s} - x_{i - r} - - * carry_{i-1}) \bmod m @f$. - * - * The size of the state is @f$ r @f$ - * and the maximum period of the generator is @f$ m^r - m^s -1 @f$. - * - * N1688[4.13] says "the template parameter _IntType shall denote an integral - * type large enough to store values up to m." - * - * @var _M_x The state of the generator. This is a ring buffer. - * @var _M_carry The carry. - * @var _M_p Current index of x(i - r). - */ - template<typename _IntType, _IntType __m, int __s, int __r> - class subtract_with_carry - { - __glibcxx_class_requires(_IntType, _IntegerConcept) - - public: - /** The type of the generated random value. */ - typedef _IntType result_type; - - // parameter values - static const _IntType modulus = __m; - static const int long_lag = __r; - static const int short_lag = __s; - - /** - * Constructs a default-initialized % subtract_with_carry random number - * generator. - */ - subtract_with_carry() - { this->seed(); } - - /** - * Constructs an explicitly seeded % subtract_with_carry random number - * generator. - */ - explicit - subtract_with_carry(unsigned long __value) - { this->seed(__value); } - - /** - * Constructs a %subtract_with_carry random number generator engine - * seeded from the generator function @p __g. - * - * @param __g The seed generator function. - */ - template<class _Gen> - subtract_with_carry(_Gen& __g) - { this->seed(__g); } - - /** - * Seeds the initial state @f$ x_0 @f$ of the random number generator. - * - * N1688[4.19] modifies this as follows. If @p __value == 0, - * sets value to 19780503. In any case, with a linear - * congruential generator lcg(i) having parameters @f$ m_{lcg} = - * 2147483563, a_{lcg} = 40014, c_{lcg} = 0, and lcg(0) = value - * @f$, sets @f$ x_{-r} \dots x_{-1} @f$ to @f$ lcg(1) \bmod m - * \dots lcg(r) \bmod m @f$ respectively. If @f$ x_{-1} = 0 @f$ - * set carry to 1, otherwise sets carry to 0. - */ - void - seed(unsigned long __value = 19780503); - - /** - * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry - * random number generator. - */ - template<class _Gen> - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - /** - * Gets the inclusive minimum value of the range of random integers - * returned by this generator. - */ - result_type - min() const - { return 0; } - - /** - * Gets the inclusive maximum value of the range of random integers - * returned by this generator. - */ - result_type - max() const - { return this->modulus - 1; } - - /** - * Gets the next random number in the sequence. - */ - result_type - operator()(); - - /** - * Compares two % subtract_with_carry random number generator objects of - * the same type for equality. - * - * @param __lhs A % subtract_with_carry random number generator object. - * @param __rhs Another % subtract_with_carry random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const subtract_with_carry& __lhs, - const subtract_with_carry& __rhs) - { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); } - - /** - * Compares two % subtract_with_carry random number generator objects of - * the same type for inequality. - * - * @param __lhs A % subtract_with_carry random number generator object. - * @param __rhs Another % subtract_with_carry random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const subtract_with_carry& __lhs, - const subtract_with_carry& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a % subtract_with_carry random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A % subtract_with_carry random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - 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<_IntType1, __m1, __s1, - __r1>& __x); - - /** - * Extracts the current state of a % subtract_with_carry random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A % subtract_with_carry random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - 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<_IntType1, __m1, __s1, __r1>& __x); - - private: - template<class _Gen> - void - seed(_Gen& __g, true_type) - { return seed(static_cast<unsigned long>(__g)); } - - template<class _Gen> - void - seed(_Gen& __g, false_type); - - typedef typename __gnu_cxx::__add_unsigned<_IntType>::__type _UIntType; - - _UIntType _M_x[long_lag]; - _UIntType _M_carry; - int _M_p; - }; - - - /** - * @brief The Marsaglia-Zaman generator (floats version). - * - * @var _M_x The state of the generator. This is a ring buffer. - * @var _M_carry The carry. - * @var _M_p Current index of x(i - r). - * @var _M_npows Precomputed negative powers of 2. - */ - template<typename _RealType, int __w, int __s, int __r> - class subtract_with_carry_01 - { - public: - /** The type of the generated random value. */ - typedef _RealType result_type; - - // parameter values - static const int word_size = __w; - static const int long_lag = __r; - static const int short_lag = __s; - - /** - * Constructs a default-initialized % subtract_with_carry_01 random - * number generator. - */ - subtract_with_carry_01() - { - this->seed(); - _M_initialize_npows(); - } - - /** - * Constructs an explicitly seeded % subtract_with_carry_01 random number - * generator. - */ - explicit - subtract_with_carry_01(unsigned long __value) - { - this->seed(__value); - _M_initialize_npows(); - } - - /** - * Constructs a % subtract_with_carry_01 random number generator engine - * seeded from the generator function @p __g. - * - * @param __g The seed generator function. - */ - template<class _Gen> - subtract_with_carry_01(_Gen& __g) - { - this->seed(__g); - _M_initialize_npows(); - } - - /** - * Seeds the initial state @f$ x_0 @f$ of the random number generator. - */ - void - seed(unsigned long __value = 19780503); - - /** - * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry_01 - * random number generator. - */ - template<class _Gen> - void - seed(_Gen& __g) - { seed(__g, typename is_fundamental<_Gen>::type()); } - - /** - * Gets the minimum value of the range of random floats - * returned by this generator. - */ - result_type - min() const - { return 0.0; } - - /** - * Gets the maximum value of the range of random floats - * returned by this generator. - */ - result_type - max() const - { return 1.0; } - - /** - * Gets the next random number in the sequence. - */ - result_type - operator()(); - - /** - * Compares two % subtract_with_carry_01 random number generator objects - * of the same type for equality. - * - * @param __lhs A % subtract_with_carry_01 random number - * generator object. - * @param __rhs Another % subtract_with_carry_01 random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const subtract_with_carry_01& __lhs, - const subtract_with_carry_01& __rhs) - { - for (int __i = 0; __i < long_lag; ++__i) - if (!std::equal(__lhs._M_x[__i], __lhs._M_x[__i] + __n, - __rhs._M_x[__i])) - return false; - return true; - } - - /** - * Compares two % subtract_with_carry_01 random number generator objects - * of the same type for inequality. - * - * @param __lhs A % subtract_with_carry_01 random number - * generator object. - * - * @param __rhs Another % subtract_with_carry_01 random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const subtract_with_carry_01& __lhs, - const subtract_with_carry_01& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a % subtract_with_carry_01 random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A % subtract_with_carry_01 random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _RealType1, int __w1, 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_01<_RealType1, __w1, __s1, - __r1>& __x); - - /** - * Extracts the current state of a % subtract_with_carry_01 random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A % subtract_with_carry_01 random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - template<typename _RealType1, int __w1, int __s1, int __r1, - typename _CharT, typename _Traits> - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry_01<_RealType1, __w1, __s1, __r1>& __x); - - private: - template<class _Gen> - void - seed(_Gen& __g, true_type) - { return seed(static_cast<unsigned long>(__g)); } - - template<class _Gen> - void - seed(_Gen& __g, false_type); - - void - _M_initialize_npows(); - - static const int __n = (__w + 31) / 32; - - typedef __detail::_UInt32Type _UInt32Type; - _UInt32Type _M_x[long_lag][__n]; - _RealType _M_npows[__n]; - _UInt32Type _M_carry; - int _M_p; - }; - - typedef subtract_with_carry_01<float, 24, 10, 24> ranlux_base_01; - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 508. Bad parameters for ranlux64_base_01. - typedef subtract_with_carry_01<double, 48, 5, 12> ranlux64_base_01; - - - /** - * Produces random numbers from some base engine by discarding blocks of - * data. - * - * 0 <= @p __r <= @p __p - */ - template<class _UniformRandomNumberGenerator, int __p, int __r> - class discard_block - { - // __glibcxx_class_requires(typename base_type::result_type, - // ArithmeticTypeConcept) - - public: - /** The type of the underlying generator engine. */ - typedef _UniformRandomNumberGenerator base_type; - /** The type of the generated random value. */ - typedef typename base_type::result_type result_type; - - // parameter values - static const int block_size = __p; - static const int used_block = __r; - - /** - * Constructs a default %discard_block engine. - * - * The underlying engine is default constructed as well. - */ - discard_block() - : _M_n(0) { } - - /** - * Copy constructs a %discard_block engine. - * - * Copies an existing base class random number generator. - * @param rng An existing (base class) engine object. - */ - explicit - discard_block(const base_type& __rng) - : _M_b(__rng), _M_n(0) { } - - /** - * Seed constructs a %discard_block engine. - * - * Constructs the underlying generator engine seeded with @p __s. - * @param __s A seed value for the base class engine. - */ - explicit - discard_block(unsigned long __s) - : _M_b(__s), _M_n(0) { } - - /** - * Generator construct a %discard_block engine. - * - * @param __g A seed generator function. - */ - template<class _Gen> - discard_block(_Gen& __g) - : _M_b(__g), _M_n(0) { } - - /** - * Reseeds the %discard_block object with the default seed for the - * underlying base class generator engine. - */ - void seed() - { - _M_b.seed(); - _M_n = 0; - } - - /** - * Reseeds the %discard_block object with the given seed generator - * function. - * @param __g A seed generator function. - */ - template<class _Gen> - void seed(_Gen& __g) - { - _M_b.seed(__g); - _M_n = 0; - } - - /** - * Gets a const reference to the underlying generator engine object. - */ - const base_type& - base() const - { return _M_b; } - - /** - * Gets the minimum value in the generated random number range. - */ - result_type - min() const - { return _M_b.min(); } - - /** - * Gets the maximum value in the generated random number range. - */ - result_type - max() const - { return _M_b.max(); } - - /** - * Gets the next value in the generated random number sequence. - */ - result_type - operator()(); - - /** - * Compares two %discard_block random number generator objects of - * the same type for equality. - * - * @param __lhs A %discard_block random number generator object. - * @param __rhs Another %discard_block random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const discard_block& __lhs, const discard_block& __rhs) - { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); } - - /** - * Compares two %discard_block random number generator objects of - * the same type for inequality. - * - * @param __lhs A %discard_block random number generator object. - * @param __rhs Another %discard_block random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const discard_block& __lhs, const discard_block& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a %discard_block random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %discard_block random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - 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<_UniformRandomNumberGenerator1, - __p1, __r1>& __x); - - /** - * Extracts the current state of a % subtract_with_carry random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %discard_block random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - 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<_UniformRandomNumberGenerator1, - __p1, __r1>& __x); - - private: - base_type _M_b; - int _M_n; - }; - - - /** - * James's luxury-level-3 integer adaptation of Luescher's generator. - */ - typedef discard_block< - subtract_with_carry<unsigned long, (1UL << 24), 10, 24>, - 223, - 24 - > ranlux3; - - /** - * James's luxury-level-4 integer adaptation of Luescher's generator. - */ - typedef discard_block< - subtract_with_carry<unsigned long, (1UL << 24), 10, 24>, - 389, - 24 - > ranlux4; - - typedef discard_block< - subtract_with_carry_01<float, 24, 10, 24>, - 223, - 24 - > ranlux3_01; - - typedef discard_block< - subtract_with_carry_01<float, 24, 10, 24>, - 389, - 24 - > ranlux4_01; - - - /** - * A random number generator adaptor class that combines two random number - * generator engines into a single output sequence. - */ - template<class _UniformRandomNumberGenerator1, int __s1, - class _UniformRandomNumberGenerator2, int __s2> - class xor_combine - { - // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1:: - // result_type, ArithmeticTypeConcept) - // __glibcxx_class_requires(typename _UniformRandomNumberGenerator2:: - // result_type, ArithmeticTypeConcept) - - public: - /** The type of the first underlying generator engine. */ - typedef _UniformRandomNumberGenerator1 base1_type; - /** The type of the second underlying generator engine. */ - typedef _UniformRandomNumberGenerator2 base2_type; - - private: - typedef typename base1_type::result_type _Result_type1; - typedef typename base2_type::result_type _Result_type2; - - public: - /** The type of the generated random value. */ - typedef typename __gnu_cxx::__conditional_type<(sizeof(_Result_type1) - > sizeof(_Result_type2)), - _Result_type1, _Result_type2>::__type result_type; - - // parameter values - static const int shift1 = __s1; - static const int shift2 = __s2; - - // constructors and member function - xor_combine() - : _M_b1(), _M_b2() - { _M_initialize_max(); } - - xor_combine(const base1_type& __rng1, const base2_type& __rng2) - : _M_b1(__rng1), _M_b2(__rng2) - { _M_initialize_max(); } - - xor_combine(unsigned long __s) - : _M_b1(__s), _M_b2(__s + 1) - { _M_initialize_max(); } - - template<class _Gen> - xor_combine(_Gen& __g) - : _M_b1(__g), _M_b2(__g) - { _M_initialize_max(); } - - void - seed() - { - _M_b1.seed(); - _M_b2.seed(); - } - - template<class _Gen> - void - seed(_Gen& __g) - { - _M_b1.seed(__g); - _M_b2.seed(__g); - } - - const base1_type& - base1() const - { return _M_b1; } - - const base2_type& - base2() const - { return _M_b2; } - - result_type - min() const - { return 0; } - - result_type - max() const - { return _M_max; } - - /** - * Gets the next random number in the sequence. - */ - // NB: Not exactly the TR1 formula, per N2079 instead. - result_type - operator()() - { - return ((result_type(_M_b1() - _M_b1.min()) << shift1) - ^ (result_type(_M_b2() - _M_b2.min()) << shift2)); - } - - /** - * Compares two %xor_combine random number generator objects of - * the same type for equality. - * - * @param __lhs A %xor_combine random number generator object. - * @param __rhs Another %xor_combine random number generator - * object. - * - * @returns true if the two objects are equal, false otherwise. - */ - friend bool - operator==(const xor_combine& __lhs, const xor_combine& __rhs) - { - return (__lhs.base1() == __rhs.base1()) - && (__lhs.base2() == __rhs.base2()); - } - - /** - * Compares two %xor_combine random number generator objects of - * the same type for inequality. - * - * @param __lhs A %xor_combine random number generator object. - * @param __rhs Another %xor_combine random number generator - * object. - * - * @returns true if the two objects are not equal, false otherwise. - */ - friend bool - operator!=(const xor_combine& __lhs, const xor_combine& __rhs) - { return !(__lhs == __rhs); } - - /** - * Inserts the current state of a %xor_combine random number - * generator engine @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %xor_combine random number generator engine. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - 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<_UniformRandomNumberGenerator11, __s11, - _UniformRandomNumberGenerator21, __s21>& __x); - - /** - * Extracts the current state of a %xor_combine random number - * generator engine @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %xor_combine random number generator engine. - * - * @returns The input stream with the state of @p __x extracted or in - * an error state. - */ - 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<_UniformRandomNumberGenerator11, __s11, - _UniformRandomNumberGenerator21, __s21>& __x); - - private: - void - _M_initialize_max(); - - result_type - _M_initialize_max_aux(result_type, result_type, int); - - base1_type _M_b1; - base2_type _M_b2; - result_type _M_max; - }; - - - /** - * A standard interface to a platform-specific non-deterministic - * random number generator (if any are available). - */ - class random_device - { - public: - // types - typedef unsigned int result_type; - - // constructors, destructors and member functions - -#ifdef _GLIBCXX_USE_RANDOM_TR1 - - explicit - random_device(const std::string& __token = "/dev/urandom") - { - if ((__token != "/dev/urandom" && __token != "/dev/random") - || !(_M_file = std::fopen(__token.c_str(), "rb"))) - std::__throw_runtime_error(__N("random_device::" - "random_device(const std::string&)")); - } - - ~random_device() - { std::fclose(_M_file); } - -#else - - explicit - random_device(const std::string& __token = "mt19937") - : _M_mt(_M_strtoul(__token)) { } - - private: - static unsigned long - _M_strtoul(const std::string& __str) - { - unsigned long __ret = 5489UL; - if (__str != "mt19937") - { - const char* __nptr = __str.c_str(); - char* __endptr; - __ret = std::strtoul(__nptr, &__endptr, 0); - if (*__nptr == '\0' || *__endptr != '\0') - std::__throw_runtime_error(__N("random_device::_M_strtoul" - "(const std::string&)")); - } - return __ret; - } - - public: - -#endif - - result_type - min() const - { return std::numeric_limits<result_type>::min(); } - - result_type - max() const - { return std::numeric_limits<result_type>::max(); } - - double - entropy() const - { return 0.0; } - - result_type - operator()() - { -#ifdef _GLIBCXX_USE_RANDOM_TR1 - result_type __ret; - std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type), - 1, _M_file); - return __ret; -#else - return _M_mt(); -#endif - } - - private: - random_device(const random_device&); - void operator=(const random_device&); - -#ifdef _GLIBCXX_USE_RANDOM_TR1 - FILE* _M_file; -#else - mt19937 _M_mt; -#endif - }; - - /* @} */ // group tr1_random_generators - - /** - * @defgroup tr1_random_distributions Random Number Distributions - * @ingroup tr1_random - * @{ - */ - - /** - * @defgroup tr1_random_distributions_discrete Discrete Distributions - * @ingroup tr1_random_distributions - * @{ - */ - - /** - * @brief Uniform discrete distribution for random numbers. - * A discrete random distribution on the range @f$[min, max]@f$ with equal - * probability throughout the range. - */ - template<typename _IntType = int> - class uniform_int - { - __glibcxx_class_requires(_IntType, _IntegerConcept) - - public: - /** The type of the parameters of the distribution. */ - typedef _IntType input_type; - /** The type of the range of the distribution. */ - typedef _IntType result_type; - - public: - /** - * Constructs a uniform distribution object. - */ - explicit - uniform_int(_IntType __min = 0, _IntType __max = 9) - : _M_min(__min), _M_max(__max) - { - _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); - } - - /** - * Gets the inclusive lower bound of the distribution range. - */ - result_type - min() const - { return _M_min; } - - /** - * Gets the inclusive upper bound of the distribution range. - */ - result_type - max() const - { return _M_max; } - - /** - * Resets the distribution state. - * - * Does nothing for the uniform integer distribution. - */ - void - reset() { } - - /** - * Gets a uniformly distributed random number in the range - * @f$(min, max)@f$. - */ - template<typename _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { - typedef typename _UniformRandomNumberGenerator::result_type - _UResult_type; - return _M_call(__urng, _M_min, _M_max, - typename is_integral<_UResult_type>::type()); - } - - /** - * Gets a uniform random number in the range @f$[0, n)@f$. - * - * This function is aimed at use with std::random_shuffle. - */ - template<typename _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng, result_type __n) - { - typedef typename _UniformRandomNumberGenerator::result_type - _UResult_type; - return _M_call(__urng, 0, __n - 1, - typename is_integral<_UResult_type>::type()); - } - - /** - * Inserts a %uniform_int random number distribution @p __x into the - * output stream @p os. - * - * @param __os An output stream. - * @param __x A %uniform_int random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _IntType1, typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_int<_IntType1>& __x); - - /** - * Extracts a %uniform_int random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %uniform_int random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template<typename _IntType1, typename _CharT, typename _Traits> - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_int<_IntType1>& __x); - - private: - template<typename _UniformRandomNumberGenerator> - result_type - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, true_type); - - template<typename _UniformRandomNumberGenerator> - result_type - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, false_type) - { - return result_type((__urng() - __urng.min()) - / (__urng.max() - __urng.min()) - * (__max - __min + 1)) + __min; - } - - _IntType _M_min; - _IntType _M_max; - }; - - - /** - * @brief A Bernoulli random number distribution. - * - * 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 - { - public: - typedef int input_type; - typedef bool result_type; - - public: - /** - * Constructs a Bernoulli distribution with likelihood @p p. - * - * @param __p [IN] The likelihood of a true result being returned. Must - * be in the interval @f$ [0, 1] @f$. - */ - explicit - bernoulli_distribution(double __p = 0.5) - : _M_p(__p) - { - _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0)); - } - - /** - * Gets the @p p parameter of the distribution. - */ - double - p() const - { return _M_p; } - - /** - * Resets the distribution state. - * - * Does nothing for a Bernoulli distribution. - */ - void - reset() { } - - /** - * Gets the next value in the Bernoullian sequence. - */ - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { - if ((__urng() - __urng.min()) < _M_p * (__urng.max() - __urng.min())) - return true; - return false; - } - - /** - * Inserts a %bernoulli_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %bernoulli_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const bernoulli_distribution& __x); - - /** - * Extracts a %bernoulli_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %bernoulli_distribution random number generator engine. - * - * @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& __x) - { return __is >> __x._M_p; } - - private: - double _M_p; - }; - - - /** - * @brief A discrete geometric random number distribution. - * - * The formula for the geometric probability mass function is - * @f$ p(i) = (1 - p)p^{i-1} @f$ where @f$ p @f$ is the parameter of the - * distribution. - */ - template<typename _IntType = int, typename _RealType = double> - class geometric_distribution - { - public: - // types - typedef _RealType input_type; - typedef _IntType result_type; - - // constructors and member function - explicit - geometric_distribution(const _RealType& __p = _RealType(0.5)) - : _M_p(__p) - { - _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) && (_M_p < 1.0)); - _M_initialize(); - } - - /** - * Gets the distribution parameter @p p. - */ - _RealType - p() const - { return _M_p; } - - void - reset() { } - - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %geometric_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %geometric_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - 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<_IntType1, _RealType1>& __x); - - /** - * Extracts a %geometric_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %geometric_distribution random number generator engine. - * - * @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& __x) - { - __is >> __x._M_p; - __x._M_initialize(); - return __is; - } - - private: - void - _M_initialize() - { _M_log_p = std::log(_M_p); } - - _RealType _M_p; - _RealType _M_log_p; - }; - - - template<typename _RealType> - class normal_distribution; - - /** - * @brief A discrete Poisson random number distribution. - * - * The formula for the Poisson probability mass function is - * @f$ p(i) = \frac{mean^i}{i!} e^{-mean} @f$ where @f$ mean @f$ is the - * parameter of the distribution. - */ - template<typename _IntType = int, typename _RealType = double> - class poisson_distribution - { - public: - // types - typedef _RealType input_type; - typedef _IntType result_type; - - // constructors and member function - explicit - poisson_distribution(const _RealType& __mean = _RealType(1)) - : _M_mean(__mean), _M_nd() - { - _GLIBCXX_DEBUG_ASSERT(_M_mean > 0.0); - _M_initialize(); - } - - /** - * Gets the distribution parameter @p mean. - */ - _RealType - mean() const - { return _M_mean; } - - void - reset() - { _M_nd.reset(); } - - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %poisson_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %poisson_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _IntType1, typename _RealType1, - typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const poisson_distribution<_IntType1, _RealType1>& __x); - - /** - * Extracts a %poisson_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %poisson_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template<typename _IntType1, typename _RealType1, - typename _CharT, typename _Traits> - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - poisson_distribution<_IntType1, _RealType1>& __x); - - private: - void - _M_initialize(); - - // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. - normal_distribution<_RealType> _M_nd; - - _RealType _M_mean; - - // Hosts either log(mean) or the threshold of the simple method. - _RealType _M_lm_thr; -#if _GLIBCXX_USE_C99_MATH_TR1 - _RealType _M_lfm, _M_sm, _M_d, _M_scx, _M_1cx, _M_c2b, _M_cb; -#endif - }; - - - /** - * @brief A discrete binomial random number distribution. - * - * The formula for the binomial probability mass function is - * @f$ p(i) = \binom{n}{i} p^i (1 - p)^{t - i} @f$ where @f$ t @f$ - * and @f$ p @f$ are the parameters of the distribution. - */ - template<typename _IntType = int, typename _RealType = double> - class binomial_distribution - { - public: - // types - typedef _RealType input_type; - typedef _IntType result_type; - - // constructors and member function - explicit - binomial_distribution(_IntType __t = 1, - const _RealType& __p = _RealType(0.5)) - : _M_t(__t), _M_p(__p), _M_nd() - { - _GLIBCXX_DEBUG_ASSERT((_M_t >= 0) && (_M_p >= 0.0) && (_M_p <= 1.0)); - _M_initialize(); - } - - /** - * Gets the distribution @p t parameter. - */ - _IntType - t() const - { return _M_t; } - - /** - * Gets the distribution @p p parameter. - */ - _RealType - p() const - { return _M_p; } - - void - reset() - { _M_nd.reset(); } - - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %binomial_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %binomial_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _IntType1, typename _RealType1, - typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const binomial_distribution<_IntType1, _RealType1>& __x); - - /** - * Extracts a %binomial_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %binomial_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template<typename _IntType1, typename _RealType1, - typename _CharT, typename _Traits> - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - binomial_distribution<_IntType1, _RealType1>& __x); - - private: - void - _M_initialize(); - - template<class _UniformRandomNumberGenerator> - result_type - _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t); - - // NB: Unused when _GLIBCXX_USE_C99_MATH_TR1 is undefined. - normal_distribution<_RealType> _M_nd; - - _RealType _M_q; -#if _GLIBCXX_USE_C99_MATH_TR1 - _RealType _M_d1, _M_d2, _M_s1, _M_s2, _M_c, - _M_a1, _M_a123, _M_s, _M_lf, _M_lp1p; -#endif - _RealType _M_p; - _IntType _M_t; - - bool _M_easy; - }; - - /* @} */ // group tr1_random_distributions_discrete - - /** - * @defgroup tr1_random_distributions_continuous Continuous Distributions - * @ingroup tr1_random_distributions - * @{ - */ - - /** - * @brief Uniform continuous distribution for random numbers. - * - * A continuous random distribution on the range [min, max) with equal - * probability throughout the range. The URNG should be real-valued and - * deliver number in the range [0, 1). - */ - template<typename _RealType = double> - class uniform_real - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs a uniform_real object. - * - * @param __min [IN] The lower bound of the distribution. - * @param __max [IN] The upper bound of the distribution. - */ - explicit - uniform_real(_RealType __min = _RealType(0), - _RealType __max = _RealType(1)) - : _M_min(__min), _M_max(__max) - { - _GLIBCXX_DEBUG_ASSERT(_M_min <= _M_max); - } - - result_type - min() const - { return _M_min; } - - result_type - max() const - { return _M_max; } - - void - reset() { } - - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { return (__urng() * (_M_max - _M_min)) + _M_min; } - - /** - * Inserts a %uniform_real random number distribution @p __x into the - * output stream @p __os. - * - * @param __os An output stream. - * @param __x A %uniform_real random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _RealType1, typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_real<_RealType1>& __x); - - /** - * Extracts a %uniform_real random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %uniform_real random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template<typename _RealType1, typename _CharT, typename _Traits> - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - uniform_real<_RealType1>& __x); - - private: - _RealType _M_min; - _RealType _M_max; - }; - - - /** - * @brief An exponential continuous distribution for random numbers. - * - * The formula for the exponential probability mass function is - * @f$ p(x) = \lambda e^{-\lambda x} @f$. - * - * <table border=1 cellpadding=10 cellspacing=0> - * <caption align=top>Distribution Statistics</caption> - * <tr><td>Mean</td><td>@f$ \frac{1}{\lambda} @f$</td></tr> - * <tr><td>Median</td><td>@f$ \frac{\ln 2}{\lambda} @f$</td></tr> - * <tr><td>Mode</td><td>@f$ zero @f$</td></tr> - * <tr><td>Range</td><td>@f$[0, \infty]@f$</td></tr> - * <tr><td>Standard Deviation</td><td>@f$ \frac{1}{\lambda} @f$</td></tr> - * </table> - */ - template<typename _RealType = double> - class exponential_distribution - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs an exponential distribution with inverse scale parameter - * @f$ \lambda @f$. - */ - explicit - exponential_distribution(const result_type& __lambda = result_type(1)) - : _M_lambda(__lambda) - { - _GLIBCXX_DEBUG_ASSERT(_M_lambda > 0); - } - - /** - * Gets the inverse scale parameter of the distribution. - */ - _RealType - lambda() const - { return _M_lambda; } - - /** - * Resets the distribution. - * - * Has no effect on exponential distributions. - */ - void - reset() { } - - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng) - { return -std::log(__urng()) / _M_lambda; } - - /** - * Inserts a %exponential_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %exponential_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _RealType1, typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const exponential_distribution<_RealType1>& __x); - - /** - * Extracts a %exponential_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %exponential_distribution random number - * generator engine. - * - * @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& __x) - { return __is >> __x._M_lambda; } - - private: - result_type _M_lambda; - }; - - - /** - * @brief A normal continuous distribution for random numbers. - * - * The formula for the normal probability mass function is - * @f$ p(x) = \frac{1}{\sigma \sqrt{2 \pi}} - * e^{- \frac{{x - mean}^ {2}}{2 \sigma ^ {2}} } @f$. - */ - template<typename _RealType = double> - class normal_distribution - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs a normal distribution with parameters @f$ mean @f$ and - * @f$ \sigma @f$. - */ - explicit - normal_distribution(const result_type& __mean = result_type(0), - const result_type& __sigma = result_type(1)) - : _M_mean(__mean), _M_sigma(__sigma), _M_saved_available(false) - { - _GLIBCXX_DEBUG_ASSERT(_M_sigma > 0); - } - - /** - * Gets the mean of the distribution. - */ - _RealType - mean() const - { return _M_mean; } - - /** - * Gets the @f$ \sigma @f$ of the distribution. - */ - _RealType - sigma() const - { return _M_sigma; } - - /** - * Resets the distribution. - */ - void - reset() - { _M_saved_available = false; } - - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %normal_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %normal_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _RealType1, typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const normal_distribution<_RealType1>& __x); - - /** - * Extracts a %normal_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %normal_distribution random number generator engine. - * - * @returns The input stream with @p __x extracted or in an error state. - */ - template<typename _RealType1, typename _CharT, typename _Traits> - friend std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - normal_distribution<_RealType1>& __x); - - private: - result_type _M_mean; - result_type _M_sigma; - result_type _M_saved; - bool _M_saved_available; - }; - - - /** - * @brief A gamma continuous distribution for random numbers. - * - * The formula for the gamma probability mass function is - * @f$ p(x) = \frac{1}{\Gamma(\alpha)} x^{\alpha - 1} e^{-x} @f$. - */ - template<typename _RealType = double> - class gamma_distribution - { - public: - // types - typedef _RealType input_type; - typedef _RealType result_type; - - public: - /** - * Constructs a gamma distribution with parameters @f$ \alpha @f$. - */ - explicit - gamma_distribution(const result_type& __alpha_val = result_type(1)) - : _M_alpha(__alpha_val) - { - _GLIBCXX_DEBUG_ASSERT(_M_alpha > 0); - _M_initialize(); - } - - /** - * Gets the @f$ \alpha @f$ of the distribution. - */ - _RealType - alpha() const - { return _M_alpha; } - - /** - * Resets the distribution. - */ - void - reset() { } - - template<class _UniformRandomNumberGenerator> - result_type - operator()(_UniformRandomNumberGenerator& __urng); - - /** - * Inserts a %gamma_distribution random number distribution - * @p __x into the output stream @p __os. - * - * @param __os An output stream. - * @param __x A %gamma_distribution random number distribution. - * - * @returns The output stream with the state of @p __x inserted or in - * an error state. - */ - template<typename _RealType1, typename _CharT, typename _Traits> - friend std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const gamma_distribution<_RealType1>& __x); - - /** - * Extracts a %gamma_distribution random number distribution - * @p __x from the input stream @p __is. - * - * @param __is An input stream. - * @param __x A %gamma_distribution random number generator engine. - * - * @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, - gamma_distribution& __x) - { - __is >> __x._M_alpha; - __x._M_initialize(); - return __is; - } - - private: - void - _M_initialize(); - - result_type _M_alpha; - - // Hosts either lambda of GB or d of modified Vaduva's. - result_type _M_l_d; - }; - - /* @} */ // group tr1_random_distributions_continuous - /* @} */ // group tr1_random_distributions - /* @} */ // group tr1_random - -_GLIBCXX_END_NAMESPACE_TR1 -} - -#include <tr1_impl/random.tcc> diff --git a/libstdc++-v3/include/tr1_impl/random.tcc b/libstdc++-v3/include/tr1_impl/random.tcc index 2b0f6957b14..e69de29bb2d 100644 --- a/libstdc++-v3/include/tr1_impl/random.tcc +++ b/libstdc++-v3/include/tr1_impl/random.tcc @@ -1,1582 +0,0 @@ -// random number generation (out of line) -*- C++ -*- - -// Copyright (C) 2007 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -/** @file tr1_impl/random.tcc - * This is an internal header file, included by other library headers. - * You should not attempt to use it directly. - */ - -namespace std -{ -_GLIBCXX_BEGIN_NAMESPACE_TR1 - - /* - * (Further) implementation-space details. - */ - namespace __detail - { - // General case for x = (ax + c) mod m -- use Schrage's algorithm to avoid - // integer overflow. - // - // Because a and c are compile-time integral constants the compiler kindly - // elides any unreachable paths. - // - // Preconditions: a > 0, m > 0. - // - template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool> - struct _Mod - { - static _Tp - __calc(_Tp __x) - { - if (__a == 1) - __x %= __m; - else - { - static const _Tp __q = __m / __a; - static const _Tp __r = __m % __a; - - _Tp __t1 = __a * (__x % __q); - _Tp __t2 = __r * (__x / __q); - if (__t1 >= __t2) - __x = __t1 - __t2; - else - __x = __m - __t2 + __t1; - } - - if (__c != 0) - { - const _Tp __d = __m - __x; - if (__d > __c) - __x += __c; - else - __x = __c - __d; - } - return __x; - } - }; - - // Special case for m == 0 -- use unsigned integer overflow as modulo - // operator. - template<typename _Tp, _Tp __a, _Tp __c, _Tp __m> - struct _Mod<_Tp, __a, __c, __m, true> - { - static _Tp - __calc(_Tp __x) - { return __a * __x + __c; } - }; - } // namespace __detail - - /** - * Seeds the LCR with integral value @p __x0, adjusted so that the - * ring identity is never a member of the convergence set. - */ - template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> - void - linear_congruential<_UIntType, __a, __c, __m>:: - seed(unsigned long __x0) - { - if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) - && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); - else - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); - } - - /** - * Seeds the LCR engine with a value generated by @p __g. - */ - template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> - template<class _Gen> - void - linear_congruential<_UIntType, __a, __c, __m>:: - seed(_Gen& __g, false_type) - { - _UIntType __x0 = __g(); - if ((__detail::__mod<_UIntType, 1, 0, __m>(__c) == 0) - && (__detail::__mod<_UIntType, 1, 0, __m>(__x0) == 0)) - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(1); - else - _M_x = __detail::__mod<_UIntType, 1, 0, __m>(__x0); - } - - /** - * Gets the next generated value in sequence. - */ - template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> - typename linear_congruential<_UIntType, __a, __c, __m>::result_type - linear_congruential<_UIntType, __a, __c, __m>:: - operator()() - { - _M_x = __detail::__mod<_UIntType, __a, __c, __m>(_M_x); - 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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - __os.flags(__ios_base::dec | __ios_base::fixed | __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) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__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, - _UIntType __b, int __t, _UIntType __c, int __l> - void - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>:: - seed(unsigned long __value) - { - _M_x[0] = __detail::__mod<_UIntType, 1, 0, - __detail::_Shift<_UIntType, __w>::__value>(__value); - - for (int __i = 1; __i < state_size; ++__i) - { - _UIntType __x = _M_x[__i - 1]; - __x ^= __x >> (__w - 2); - __x *= 1812433253ul; - __x += __i; - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, - __detail::_Shift<_UIntType, __w>::__value>(__x); - } - _M_p = state_size; - } - - 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> - template<class _Gen> - void - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>:: - seed(_Gen& __gen, false_type) - { - for (int __i = 0; __i < state_size; ++__i) - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, - __detail::_Shift<_UIntType, __w>::__value>(__gen()); - _M_p = state_size; - } - - 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 - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>::result_type - mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s, - __b, __t, __c, __l>:: - operator()() - { - // Reload the vector - cost is O(n) amortized over n calls. - if (_M_p >= state_size) - { - const _UIntType __upper_mask = (~_UIntType()) << __r; - const _UIntType __lower_mask = ~__upper_mask; - - for (int __k = 0; __k < (__n - __m); ++__k) - { - _UIntType __y = ((_M_x[__k] & __upper_mask) - | (_M_x[__k + 1] & __lower_mask)); - _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1) - ^ ((__y & 0x01) ? __a : 0)); - } - - for (int __k = (__n - __m); __k < (__n - 1); ++__k) - { - _UIntType __y = ((_M_x[__k] & __upper_mask) - | (_M_x[__k + 1] & __lower_mask)); - _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1) - ^ ((__y & 0x01) ? __a : 0)); - } - - _UIntType __y = ((_M_x[__n - 1] & __upper_mask) - | (_M_x[0] & __lower_mask)); - _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1) - ^ ((__y & 0x01) ? __a : 0)); - _M_p = 0; - } - - // Calculate o(x(i)). - result_type __z = _M_x[_M_p++]; - __z ^= (__z >> __u); - __z ^= (__z << __s) & __b; - __z ^= (__z << __t) & __c; - __z ^= (__z >> __l); - - 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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __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) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __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 - subtract_with_carry<_IntType, __m, __s, __r>:: - seed(unsigned long __value) - { - if (__value == 0) - __value = 19780503; - - std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563> - __lcg(__value); - - for (int __i = 0; __i < long_lag; ++__i) - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__lcg()); - - _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; - _M_p = 0; - } - - template<typename _IntType, _IntType __m, int __s, int __r> - template<class _Gen> - void - subtract_with_carry<_IntType, __m, __s, __r>:: - seed(_Gen& __gen, false_type) - { - const int __n = (std::numeric_limits<_UIntType>::digits + 31) / 32; - - for (int __i = 0; __i < long_lag; ++__i) - { - _UIntType __tmp = 0; - _UIntType __factor = 1; - for (int __j = 0; __j < __n; ++__j) - { - __tmp += __detail::__mod<__detail::_UInt32Type, 1, 0, 0> - (__gen()) * __factor; - __factor *= __detail::_Shift<_UIntType, 32>::__value; - } - _M_x[__i] = __detail::__mod<_UIntType, 1, 0, modulus>(__tmp); - } - _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; - _M_p = 0; - } - - template<typename _IntType, _IntType __m, int __s, int __r> - typename subtract_with_carry<_IntType, __m, __s, __r>::result_type - subtract_with_carry<_IntType, __m, __s, __r>:: - operator()() - { - // Derive short lag index from current index. - int __ps = _M_p - short_lag; - if (__ps < 0) - __ps += long_lag; - - // Calculate new x(i) without overflow or division. - // NB: Thanks to the requirements for _IntType, _M_x[_M_p] + _M_carry - // cannot overflow. - _UIntType __xi; - if (_M_x[__ps] >= _M_x[_M_p] + _M_carry) - { - __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry; - _M_carry = 0; - } - else - { - __xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps]; - _M_carry = 1; - } - _M_x[_M_p] = __xi; - - // Adjust current index to loop around in ring buffer. - if (++_M_p >= long_lag) - _M_p = 0; - - 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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __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) - { - typedef std::basic_ostream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __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<typename _RealType, int __w, int __s, int __r> - void - subtract_with_carry_01<_RealType, __w, __s, __r>:: - _M_initialize_npows() - { - for (int __j = 0; __j < __n; ++__j) -#if _GLIBCXX_USE_C99_MATH_TR1 - _M_npows[__j] = std::_GLIBCXX_TR1 ldexp(_RealType(1), -__w + __j * 32); -#else - _M_npows[__j] = std::pow(_RealType(2), -__w + __j * 32); -#endif - } - - template<typename _RealType, int __w, int __s, int __r> - void - subtract_with_carry_01<_RealType, __w, __s, __r>:: - seed(unsigned long __value) - { - if (__value == 0) - __value = 19780503; - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 512. Seeding subtract_with_carry_01 from a single unsigned long. - std::_GLIBCXX_TR1 linear_congruential<unsigned long, 40014, 0, 2147483563> - __lcg(__value); - - this->seed(__lcg); - } - - template<typename _RealType, int __w, int __s, int __r> - template<class _Gen> - void - subtract_with_carry_01<_RealType, __w, __s, __r>:: - seed(_Gen& __gen, false_type) - { - for (int __i = 0; __i < long_lag; ++__i) - { - for (int __j = 0; __j < __n - 1; ++__j) - _M_x[__i][__j] = __detail::__mod<_UInt32Type, 1, 0, 0>(__gen()); - _M_x[__i][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, - __detail::_Shift<_UInt32Type, __w % 32>::__value>(__gen()); - } - - _M_carry = 1; - for (int __j = 0; __j < __n; ++__j) - if (_M_x[long_lag - 1][__j] != 0) - { - _M_carry = 0; - break; - } - - _M_p = 0; - } - - template<typename _RealType, int __w, int __s, int __r> - typename subtract_with_carry_01<_RealType, __w, __s, __r>::result_type - subtract_with_carry_01<_RealType, __w, __s, __r>:: - operator()() - { - // Derive short lag index from current index. - int __ps = _M_p - short_lag; - if (__ps < 0) - __ps += long_lag; - - _UInt32Type __new_carry; - for (int __j = 0; __j < __n - 1; ++__j) - { - if (_M_x[__ps][__j] > _M_x[_M_p][__j] - || (_M_x[__ps][__j] == _M_x[_M_p][__j] && _M_carry == 0)) - __new_carry = 0; - else - __new_carry = 1; - - _M_x[_M_p][__j] = _M_x[__ps][__j] - _M_x[_M_p][__j] - _M_carry; - _M_carry = __new_carry; - } - - if (_M_x[__ps][__n - 1] > _M_x[_M_p][__n - 1] - || (_M_x[__ps][__n - 1] == _M_x[_M_p][__n - 1] && _M_carry == 0)) - __new_carry = 0; - else - __new_carry = 1; - - _M_x[_M_p][__n - 1] = __detail::__mod<_UInt32Type, 1, 0, - __detail::_Shift<_UInt32Type, __w % 32>::__value> - (_M_x[__ps][__n - 1] - _M_x[_M_p][__n - 1] - _M_carry); - _M_carry = __new_carry; - - result_type __ret = 0.0; - for (int __j = 0; __j < __n; ++__j) - __ret += _M_x[_M_p][__j] * _M_npows[__j]; - - // Adjust current index to loop around in ring buffer. - if (++_M_p >= long_lag) - _M_p = 0; - - return __ret; - } - - template<typename _RealType, int __w, int __s, int __r, - typename _CharT, typename _Traits> - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const subtract_with_carry_01<_RealType, __w, __s, __r>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __ios_base::left); - __os.fill(__space); - - for (int __i = 0; __i < __r; ++__i) - for (int __j = 0; __j < __x.__n; ++__j) - __os << __x._M_x[__i][__j] << __space; - __os << __x._M_carry; - - __os.flags(__flags); - __os.fill(__fill); - return __os; - } - - template<typename _RealType, int __w, int __s, int __r, - typename _CharT, typename _Traits> - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - subtract_with_carry_01<_RealType, __w, __s, __r>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - for (int __i = 0; __i < __r; ++__i) - for (int __j = 0; __j < __x.__n; ++__j) - __is >> __x._M_x[__i][__j]; - __is >> __x._M_carry; - - __is.flags(__flags); - return __is; - } - - - template<class _UniformRandomNumberGenerator, int __p, int __r> - typename discard_block<_UniformRandomNumberGenerator, - __p, __r>::result_type - discard_block<_UniformRandomNumberGenerator, __p, __r>:: - operator()() - { - if (_M_n >= used_block) - { - while (_M_n < block_size) - { - _M_b(); - ++_M_n; - } - _M_n = 0; - } - ++_M_n; - 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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed - | __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) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - __is >> __x._M_b >> __x._M_n; - - __is.flags(__flags); - return __is; - } - - - template<class _UniformRandomNumberGenerator1, int __s1, - class _UniformRandomNumberGenerator2, int __s2> - void - xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>:: - _M_initialize_max() - { - const int __w = std::numeric_limits<result_type>::digits; - - const result_type __m1 = - std::min(result_type(_M_b1.max() - _M_b1.min()), - __detail::_Shift<result_type, __w - __s1>::__value - 1); - - const result_type __m2 = - std::min(result_type(_M_b2.max() - _M_b2.min()), - __detail::_Shift<result_type, __w - __s2>::__value - 1); - - // NB: In TR1 s1 is not required to be >= s2. - if (__s1 < __s2) - _M_max = _M_initialize_max_aux(__m2, __m1, __s2 - __s1) << __s1; - else - _M_max = _M_initialize_max_aux(__m1, __m2, __s1 - __s2) << __s2; - } - - template<class _UniformRandomNumberGenerator1, int __s1, - class _UniformRandomNumberGenerator2, int __s2> - typename xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>::result_type - xor_combine<_UniformRandomNumberGenerator1, __s1, - _UniformRandomNumberGenerator2, __s2>:: - _M_initialize_max_aux(result_type __a, result_type __b, int __d) - { - const result_type __two2d = result_type(1) << __d; - const result_type __c = __a * __two2d; - - if (__a == 0 || __b < __two2d) - return __c + __b; - - const result_type __t = std::max(__c, __b); - const result_type __u = std::min(__c, __b); - - result_type __ub = __u; - result_type __p; - for (__p = 0; __ub != 1; __ub >>= 1) - ++__p; - - const result_type __two2p = result_type(1) << __p; - const result_type __k = __t / __two2p; - - if (__k & 1) - return (__k + 1) * __two2p - 1; - - if (__c >= __b) - return (__k + 1) * __two2p + _M_initialize_max_aux((__t % __two2p) - / __two2d, - __u % __two2p, __d); - else - return (__k + 1) * __two2p + _M_initialize_max_aux((__u % __two2p) - / __two2d, - __t % __two2p, __d); - } - - 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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::dec | __ios_base::fixed | __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) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::skipws); - - __is >> __x._M_b1 >> __x._M_b2; - - __is.flags(__flags); - return __is; - } - - - template<typename _IntType> - template<typename _UniformRandomNumberGenerator> - typename uniform_int<_IntType>::result_type - uniform_int<_IntType>:: - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, true_type) - { - // XXX Must be fixed to work well for *arbitrary* __urng.max(), - // __urng.min(), __max, __min. Currently works fine only in the - // most common case __urng.max() - __urng.min() >= __max - __min, - // with __urng.max() > __urng.min() >= 0. - typedef typename __gnu_cxx::__add_unsigned<typename - _UniformRandomNumberGenerator::result_type>::__type __urntype; - typedef typename __gnu_cxx::__add_unsigned<result_type>::__type - __utype; - typedef typename __gnu_cxx::__conditional_type<(sizeof(__urntype) - > sizeof(__utype)), - __urntype, __utype>::__type __uctype; - - result_type __ret; - - const __urntype __urnmin = __urng.min(); - const __urntype __urnmax = __urng.max(); - const __urntype __urnrange = __urnmax - __urnmin; - const __uctype __urange = __max - __min; - const __uctype __udenom = (__urnrange <= __urange - ? 1 : __urnrange / (__urange + 1)); - do - __ret = (__urntype(__urng()) - __urnmin) / __udenom; - while (__ret > __max - __min); - - return __ret + __min; - } - - template<typename _IntType, typename _CharT, typename _Traits> - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const uniform_int<_IntType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __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) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits<double>::__max_digits10); - - __os << __x.p(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - - template<typename _IntType, typename _RealType> - template<class _UniformRandomNumberGenerator> - typename geometric_distribution<_IntType, _RealType>::result_type - geometric_distribution<_IntType, _RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - // About the epsilon thing see this thread: - // http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00971.html - const _RealType __naf = - (1 - std::numeric_limits<_RealType>::epsilon()) / 2; - // The largest _RealType convertible to _IntType. - const _RealType __thr = - std::numeric_limits<_IntType>::max() + __naf; - - _RealType __cand; - do - __cand = std::ceil(std::log(__urng()) / _M_log_p); - while (__cand >= __thr); - - return result_type(__cand + __naf); - } - - 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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.p(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - - template<typename _IntType, typename _RealType> - void - poisson_distribution<_IntType, _RealType>:: - _M_initialize() - { -#if _GLIBCXX_USE_C99_MATH_TR1 - if (_M_mean >= 12) - { - const _RealType __m = std::floor(_M_mean); - _M_lm_thr = std::log(_M_mean); - _M_lfm = std::_GLIBCXX_TR1 lgamma(__m + 1); - _M_sm = std::sqrt(__m); - - const _RealType __pi_4 = 0.7853981633974483096156608458198757L; - const _RealType __dx = std::sqrt(2 * __m * std::log(32 * __m - / __pi_4)); - _M_d = std::_GLIBCXX_TR1 round(std::max(_RealType(6), - std::min(__m, __dx))); - const _RealType __cx = 2 * __m + _M_d; - _M_scx = std::sqrt(__cx / 2); - _M_1cx = 1 / __cx; - - _M_c2b = std::sqrt(__pi_4 * __cx) * std::exp(_M_1cx); - _M_cb = 2 * __cx * std::exp(-_M_d * _M_1cx * (1 + _M_d / 2)) / _M_d; - } - else -#endif - _M_lm_thr = std::exp(-_M_mean); - } - - /** - * A rejection algorithm when mean >= 12 and a simple method based - * upon the multiplication of uniform random variates otherwise. - * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 - * is defined. - * - * Reference: - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. X, Sects. 3.3 & 3.4 (+ Errata!). - */ - template<typename _IntType, typename _RealType> - template<class _UniformRandomNumberGenerator> - typename poisson_distribution<_IntType, _RealType>::result_type - poisson_distribution<_IntType, _RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { -#if _GLIBCXX_USE_C99_MATH_TR1 - if (_M_mean >= 12) - { - _RealType __x; - - // See comments above... - const _RealType __naf = - (1 - std::numeric_limits<_RealType>::epsilon()) / 2; - const _RealType __thr = - std::numeric_limits<_IntType>::max() + __naf; - - const _RealType __m = std::floor(_M_mean); - // sqrt(pi / 2) - const _RealType __spi_2 = 1.2533141373155002512078826424055226L; - const _RealType __c1 = _M_sm * __spi_2; - const _RealType __c2 = _M_c2b + __c1; - const _RealType __c3 = __c2 + 1; - const _RealType __c4 = __c3 + 1; - // e^(1 / 78) - const _RealType __e178 = 1.0129030479320018583185514777512983L; - const _RealType __c5 = __c4 + __e178; - const _RealType __c = _M_cb + __c5; - const _RealType __2cx = 2 * (2 * __m + _M_d); - - bool __reject = true; - do - { - const _RealType __u = __c * __urng(); - const _RealType __e = -std::log(__urng()); - - _RealType __w = 0.0; - - if (__u <= __c1) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = -std::abs(__n) * _M_sm - 1; - __x = std::floor(__y); - __w = -__n * __n / 2; - if (__x < -__m) - continue; - } - else if (__u <= __c2) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = 1 + std::abs(__n) * _M_scx; - __x = std::ceil(__y); - __w = __y * (2 - __y) * _M_1cx; - if (__x > _M_d) - continue; - } - else if (__u <= __c3) - // NB: This case not in the book, nor in the Errata, - // but should be ok... - __x = -1; - else if (__u <= __c4) - __x = 0; - else if (__u <= __c5) - __x = 1; - else - { - const _RealType __v = -std::log(__urng()); - const _RealType __y = _M_d + __v * __2cx / _M_d; - __x = std::ceil(__y); - __w = -_M_d * _M_1cx * (1 + __y / 2); - } - - __reject = (__w - __e - __x * _M_lm_thr - > _M_lfm - std::_GLIBCXX_TR1 lgamma(__x + __m + 1)); - - __reject |= __x + __m >= __thr; - - } while (__reject); - - return result_type(__x + __m + __naf); - } - else -#endif - { - _IntType __x = 0; - _RealType __prod = 1.0; - - do - { - __prod *= __urng(); - __x += 1; - } - while (__prod > _M_lm_thr); - - return __x - 1; - } - } - - template<typename _IntType, typename _RealType, - typename _CharT, typename _Traits> - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const poisson_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.mean() << __space << __x._M_nd; - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - template<typename _IntType, typename _RealType, - typename _CharT, typename _Traits> - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - poisson_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::skipws); - - __is >> __x._M_mean >> __x._M_nd; - __x._M_initialize(); - - __is.flags(__flags); - return __is; - } - - - template<typename _IntType, typename _RealType> - void - binomial_distribution<_IntType, _RealType>:: - _M_initialize() - { - const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; - - _M_easy = true; - -#if _GLIBCXX_USE_C99_MATH_TR1 - if (_M_t * __p12 >= 8) - { - _M_easy = false; - const _RealType __np = std::floor(_M_t * __p12); - const _RealType __pa = __np / _M_t; - const _RealType __1p = 1 - __pa; - - const _RealType __pi_4 = 0.7853981633974483096156608458198757L; - const _RealType __d1x = - std::sqrt(__np * __1p * std::log(32 * __np - / (81 * __pi_4 * __1p))); - _M_d1 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d1x)); - const _RealType __d2x = - std::sqrt(__np * __1p * std::log(32 * _M_t * __1p - / (__pi_4 * __pa))); - _M_d2 = std::_GLIBCXX_TR1 round(std::max(_RealType(1), __d2x)); - - // sqrt(pi / 2) - const _RealType __spi_2 = 1.2533141373155002512078826424055226L; - _M_s1 = std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np)); - _M_s2 = std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * _M_t * __1p)); - _M_c = 2 * _M_d1 / __np; - _M_a1 = std::exp(_M_c) * _M_s1 * __spi_2; - const _RealType __a12 = _M_a1 + _M_s2 * __spi_2; - const _RealType __s1s = _M_s1 * _M_s1; - _M_a123 = __a12 + (std::exp(_M_d1 / (_M_t * __1p)) - * 2 * __s1s / _M_d1 - * std::exp(-_M_d1 * _M_d1 / (2 * __s1s))); - const _RealType __s2s = _M_s2 * _M_s2; - _M_s = (_M_a123 + 2 * __s2s / _M_d2 - * std::exp(-_M_d2 * _M_d2 / (2 * __s2s))); - _M_lf = (std::_GLIBCXX_TR1 lgamma(__np + 1) - + std::_GLIBCXX_TR1 lgamma(_M_t - __np + 1)); - _M_lp1p = std::log(__pa / __1p); - - _M_q = -std::log(1 - (__p12 - __pa) / __1p); - } - else -#endif - _M_q = -std::log(1 - __p12); - } - - template<typename _IntType, typename _RealType> - template<class _UniformRandomNumberGenerator> - typename binomial_distribution<_IntType, _RealType>::result_type - binomial_distribution<_IntType, _RealType>:: - _M_waiting(_UniformRandomNumberGenerator& __urng, _IntType __t) - { - _IntType __x = 0; - _RealType __sum = 0; - - do - { - const _RealType __e = -std::log(__urng()); - __sum += __e / (__t - __x); - __x += 1; - } - while (__sum <= _M_q); - - return __x - 1; - } - - /** - * A rejection algorithm when t * p >= 8 and a simple waiting time - * method - the second in the referenced book - otherwise. - * NB: The former is available only if _GLIBCXX_USE_C99_MATH_TR1 - * is defined. - * - * Reference: - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. X, Sect. 4 (+ Errata!). - */ - template<typename _IntType, typename _RealType> - template<class _UniformRandomNumberGenerator> - typename binomial_distribution<_IntType, _RealType>::result_type - binomial_distribution<_IntType, _RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - result_type __ret; - const _RealType __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p; - -#if _GLIBCXX_USE_C99_MATH_TR1 - if (!_M_easy) - { - _RealType __x; - - // See comments above... - const _RealType __naf = - (1 - std::numeric_limits<_RealType>::epsilon()) / 2; - const _RealType __thr = - std::numeric_limits<_IntType>::max() + __naf; - - const _RealType __np = std::floor(_M_t * __p12); - const _RealType __pa = __np / _M_t; - - // sqrt(pi / 2) - const _RealType __spi_2 = 1.2533141373155002512078826424055226L; - const _RealType __a1 = _M_a1; - const _RealType __a12 = __a1 + _M_s2 * __spi_2; - const _RealType __a123 = _M_a123; - const _RealType __s1s = _M_s1 * _M_s1; - const _RealType __s2s = _M_s2 * _M_s2; - - bool __reject; - do - { - const _RealType __u = _M_s * __urng(); - - _RealType __v; - - if (__u <= __a1) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = _M_s1 * std::abs(__n); - __reject = __y >= _M_d1; - if (!__reject) - { - const _RealType __e = -std::log(__urng()); - __x = std::floor(__y); - __v = -__e - __n * __n / 2 + _M_c; - } - } - else if (__u <= __a12) - { - const _RealType __n = _M_nd(__urng); - const _RealType __y = _M_s2 * std::abs(__n); - __reject = __y >= _M_d2; - if (!__reject) - { - const _RealType __e = -std::log(__urng()); - __x = std::floor(-__y); - __v = -__e - __n * __n / 2; - } - } - else if (__u <= __a123) - { - const _RealType __e1 = -std::log(__urng()); - const _RealType __e2 = -std::log(__urng()); - - const _RealType __y = _M_d1 + 2 * __s1s * __e1 / _M_d1; - __x = std::floor(__y); - __v = (-__e2 + _M_d1 * (1 / (_M_t - __np) - -__y / (2 * __s1s))); - __reject = false; - } - else - { - const _RealType __e1 = -std::log(__urng()); - const _RealType __e2 = -std::log(__urng()); - - const _RealType __y = _M_d2 + 2 * __s2s * __e1 / _M_d2; - __x = std::floor(-__y); - __v = -__e2 - _M_d2 * __y / (2 * __s2s); - __reject = false; - } - - __reject = __reject || __x < -__np || __x > _M_t - __np; - if (!__reject) - { - const _RealType __lfx = - std::_GLIBCXX_TR1 lgamma(__np + __x + 1) - + std::_GLIBCXX_TR1 lgamma(_M_t - (__np + __x) + 1); - __reject = __v > _M_lf - __lfx + __x * _M_lp1p; - } - - __reject |= __x + __np >= __thr; - } - while (__reject); - - __x += __np + __naf; - - const _IntType __z = _M_waiting(__urng, _M_t - _IntType(__x)); - __ret = _IntType(__x) + __z; - } - else -#endif - __ret = _M_waiting(__urng, _M_t); - - if (__p12 != _M_p) - __ret = _M_t - __ret; - return __ret; - } - - template<typename _IntType, typename _RealType, - typename _CharT, typename _Traits> - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const binomial_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.t() << __space << __x.p() - << __space << __x._M_nd; - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - template<typename _IntType, typename _RealType, - typename _CharT, typename _Traits> - std::basic_istream<_CharT, _Traits>& - operator>>(std::basic_istream<_CharT, _Traits>& __is, - binomial_distribution<_IntType, _RealType>& __x) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - __is >> __x._M_t >> __x._M_p >> __x._M_nd; - __x._M_initialize(); - - __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 uniform_real<_RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __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) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__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) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.lambda(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - - - /** - * Polar method due to Marsaglia. - * - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. V, Sect. 4.4. - */ - template<typename _RealType> - template<class _UniformRandomNumberGenerator> - typename normal_distribution<_RealType>::result_type - normal_distribution<_RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - result_type __ret; - - if (_M_saved_available) - { - _M_saved_available = false; - __ret = _M_saved; - } - else - { - result_type __x, __y, __r2; - do - { - __x = result_type(2.0) * __urng() - 1.0; - __y = result_type(2.0) * __urng() - 1.0; - __r2 = __x * __x + __y * __y; - } - while (__r2 > 1.0 || __r2 == 0.0); - - const result_type __mult = std::sqrt(-2 * std::log(__r2) / __r2); - _M_saved = __x * __mult; - _M_saved_available = true; - __ret = __y * __mult; - } - - __ret = __ret * _M_sigma + _M_mean; - return __ret; - } - - template<typename _RealType, typename _CharT, typename _Traits> - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const normal_distribution<_RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - const _CharT __space = __os.widen(' '); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__space); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x._M_saved_available << __space - << __x.mean() << __space - << __x.sigma(); - if (__x._M_saved_available) - __os << __space << __x._M_saved; - - __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) - { - typedef std::basic_istream<_CharT, _Traits> __istream_type; - typedef typename __istream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __is.flags(); - __is.flags(__ios_base::dec | __ios_base::skipws); - - __is >> __x._M_saved_available >> __x._M_mean - >> __x._M_sigma; - if (__x._M_saved_available) - __is >> __x._M_saved; - - __is.flags(__flags); - return __is; - } - - - template<typename _RealType> - void - gamma_distribution<_RealType>:: - _M_initialize() - { - if (_M_alpha >= 1) - _M_l_d = std::sqrt(2 * _M_alpha - 1); - else - _M_l_d = (std::pow(_M_alpha, _M_alpha / (1 - _M_alpha)) - * (1 - _M_alpha)); - } - - /** - * Cheng's rejection algorithm GB for alpha >= 1 and a modification - * of Vaduva's rejection from Weibull algorithm due to Devroye for - * alpha < 1. - * - * References: - * Cheng, R. C. "The Generation of Gamma Random Variables with Non-integral - * Shape Parameter." Applied Statistics, 26, 71-75, 1977. - * - * Vaduva, I. "Computer Generation of Gamma Gandom Variables by Rejection - * and Composition Procedures." Math. Operationsforschung and Statistik, - * Series in Statistics, 8, 545-576, 1977. - * - * Devroye, L. "Non-Uniform Random Variates Generation." Springer-Verlag, - * New York, 1986, Ch. IX, Sect. 3.4 (+ Errata!). - */ - template<typename _RealType> - template<class _UniformRandomNumberGenerator> - typename gamma_distribution<_RealType>::result_type - gamma_distribution<_RealType>:: - operator()(_UniformRandomNumberGenerator& __urng) - { - result_type __x; - - bool __reject; - if (_M_alpha >= 1) - { - // alpha - log(4) - const result_type __b = _M_alpha - - result_type(1.3862943611198906188344642429163531L); - const result_type __c = _M_alpha + _M_l_d; - const result_type __1l = 1 / _M_l_d; - - // 1 + log(9 / 2) - const result_type __k = 2.5040773967762740733732583523868748L; - - do - { - const result_type __u = __urng(); - const result_type __v = __urng(); - - const result_type __y = __1l * std::log(__v / (1 - __v)); - __x = _M_alpha * std::exp(__y); - - const result_type __z = __u * __v * __v; - const result_type __r = __b + __c * __y - __x; - - __reject = __r < result_type(4.5) * __z - __k; - if (__reject) - __reject = __r < std::log(__z); - } - while (__reject); - } - else - { - const result_type __c = 1 / _M_alpha; - - do - { - const result_type __z = -std::log(__urng()); - const result_type __e = -std::log(__urng()); - - __x = std::pow(__z, __c); - - __reject = __z + __e < _M_l_d + __x; - } - while (__reject); - } - - return __x; - } - - template<typename _RealType, typename _CharT, typename _Traits> - std::basic_ostream<_CharT, _Traits>& - operator<<(std::basic_ostream<_CharT, _Traits>& __os, - const gamma_distribution<_RealType>& __x) - { - typedef std::basic_ostream<_CharT, _Traits> __ostream_type; - typedef typename __ostream_type::ios_base __ios_base; - - const typename __ios_base::fmtflags __flags = __os.flags(); - const _CharT __fill = __os.fill(); - const std::streamsize __precision = __os.precision(); - __os.flags(__ios_base::scientific | __ios_base::left); - __os.fill(__os.widen(' ')); - __os.precision(__gnu_cxx::__numeric_traits<_RealType>::__max_digits10); - - __os << __x.alpha(); - - __os.flags(__flags); - __os.fill(__fill); - __os.precision(__precision); - return __os; - } - -_GLIBCXX_END_NAMESPACE_TR1 -} diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc index 5bdd65c2700..9a206bfbc18 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2006, 2007, 2008 Free Software Foundation +// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -85,11 +85,12 @@ void* thread_hammer_and_kill(void* opaque_pools) { shared_and_weak_pools& pools = *static_cast<shared_and_weak_pools*>(opaque_pools); // Using the same parameters as in the RNG test cases. - std::mersenne_twister< + std::mersenne_twister_engine< unsigned long, 32, 624, 397, 31, - 0x9908b0dful, 11, 7, + 0x9908b0dful, 11, + 0xfffffffful, 7, 0x9d2c5680ul, 15, - 0xefc60000ul, 18> rng; + 0xefc60000ul, 18, 1812433253ul> rng; sp_vector_t::iterator cur_shared = pools.shared_pool.begin(); wp_vector_t::iterator cur_weak = pools.weak_pool.begin(); @@ -120,11 +121,13 @@ void* thread_hammer(void* opaque_weak) { wp_vector_t& weak_pool = *static_cast<wp_vector_t*>(opaque_weak); // Using the same parameters as in the RNG test cases. - std::mersenne_twister< + std::mersenne_twister_engine< unsigned long, 32, 624, 397, 31, - 0x9908b0dful, 11, 7, + 0x9908b0dful, 11, + 0xfffffffful, 7, 0x9d2c5680ul, 15, - 0xefc60000ul, 18> rng; + 0xefc60000ul, 18, 1812433253ul> rng; + wp_vector_t::iterator cur_weak = weak_pool.begin(); for (unsigned int i = 0; i < HAMMER_REPEAT; ++i) diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc index 20c2da146e0..f98cbfeb089 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2006, 2007, 2008 Free Software Foundation +// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -87,12 +87,13 @@ void* thread_hammer_and_kill(void* opaque_pools) { shared_and_weak_pools& pools = *static_cast<shared_and_weak_pools*>(opaque_pools); // Using the same parameters as in the RNG test cases. - std::mersenne_twister< + std::mersenne_twister_engine< unsigned long, 32, 624, 397, 31, - 0x9908b0dful, 11, 7, + 0x9908b0dful, 11, + 0xfffffffful, 7, 0x9d2c5680ul, 15, - 0xefc60000ul, 18> rng; - + 0xefc60000ul, 18, 1812433253ul> rng; + sp_vector_t::iterator cur_shared = pools.shared_pool.begin(); wp_vector_t::iterator cur_weak = pools.weak_pool.begin(); @@ -122,11 +123,13 @@ void* thread_hammer(void* opaque_weak) { wp_vector_t& weak_pool = *static_cast<wp_vector_t*>(opaque_weak); // Using the same parameters as in the RNG test cases. - std::mersenne_twister< + std::mersenne_twister_engine< unsigned long, 32, 624, 397, 31, - 0x9908b0dful, 11, 7, + 0x9908b0dful, 11, + 0xfffffffful, 7, 0x9d2c5680ul, 15, - 0xefc60000ul, 18> rng; + 0xefc60000ul, 18, 1812433253ul> rng; + wp_vector_t::iterator cur_weak = weak_pool.begin(); for (unsigned int i = 0; i < HAMMER_REPEAT; ++i) diff --git a/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc b/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc index 9b028bc0324..e91efd17539 100644 --- a/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/headers/random/std_c++0x_neg.cc @@ -19,7 +19,7 @@ // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. -#include <tuple> // { dg-excess-errors "In file included from" } +#include <random> // { dg-excess-errors "In file included from" } // { dg-error "upcoming ISO" "" { target *-*-* } 36 } diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/default.cc new file mode 100644 index 00000000000..1ca07fe255c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/default.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::bernoulli_distribution u; + VERIFY( u.p() == 0.5 ); + VERIFY( u.min() == std::numeric_limits<bool>::min() ); + VERIFY( u.max() == std::numeric_limits<bool>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/parms.cc new file mode 100644 index 00000000000..05d4dbedb05 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/cons/parms.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::bernoulli_distribution u(0.75); + VERIFY( u.p() == 0.75 ); + VERIFY( u.min() == std::numeric_limits<bool>::min() ); + VERIFY( u.max() == std::numeric_limits<bool>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/operators/serialize.cc new file mode 100644 index 00000000000..a8a753347ca --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::bernoulli_distribution u(0.75), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..5105cbb0d78 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/bernoulli_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.1 Class template bernoulli_distribution [rand.dist.bern.bernoulli] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::bernoulli_distribution test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/default.cc new file mode 100644 index 00000000000..62957923360 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::binomial_distribution<> u; + VERIFY( u.t() == 1 ); + VERIFY( u.p() == 0.5 ); + VERIFY( u.min() == 0 ); + VERIFY( u.max() == u.t() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/parms.cc new file mode 100644 index 00000000000..0a427fe13df --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::binomial_distribution<> u(3, 0.75); + VERIFY( u.t() == 3 ); + VERIFY( u.p() == 0.75 ); + VERIFY( u.min() == 0 ); + VERIFY( u.max() == u.t() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/serialize.cc new file mode 100644 index 00000000000..8aec5f1d23c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::binomial_distribution<int> u(3, 0.75), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..521d124341a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/binomial_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.2 Class template binomial_distribution [rand.dist.bern.bin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::binomial_distribution<int> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/default.cc new file mode 100644 index 00000000000..67e8d368f9c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.4 Class template cauchy_distribution [rand.dist.norm.cauchy] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::cauchy_distribution<> u; + VERIFY( u.a() == 0.0 ); + VERIFY( u.b() == 1.0 ); + typedef std::cauchy_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/parms.cc new file mode 100644 index 00000000000..08d6c6b15a0 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.4 Class template cauchy_distribution [rand.dist.norm.cauchy] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::cauchy_distribution<> u(5.0, 2.0); + VERIFY( u.a() == 5.0 ); + VERIFY( u.b() == 2.0 ); + typedef std::cauchy_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/operators/serialize.cc new file mode 100644 index 00000000000..a1fb165ef60 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::cauchy_distribution<double> u(5.0, 2.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..192f85c1614 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/cauchy_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.4 Class template cauchy_distribution [rand.dist.norm.cauchy] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::cauchy_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/default.cc new file mode 100644 index 00000000000..3441a207e0d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::chi_squared_distribution<> u; + VERIFY( u.n() == 1 ); + typedef std::chi_squared_distribution<>::result_type result_type; + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/parms.cc new file mode 100644 index 00000000000..f457a9ebc45 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::chi_squared_distribution<> u(1.5); + VERIFY( u.n() == 1.5 ); + typedef std::chi_squared_distribution<>::result_type result_type; + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/operators/serialize.cc new file mode 100644 index 00000000000..927e137f49a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::chi_squared_distribution<double> u(1.5), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..e110dbdd9ef --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/chi_squared_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.3 Class template chi_squared_distribution [rand.dist.norm.chisq] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::chi_squared_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc b/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc new file mode 100644 index 00000000000..2886f2dd669 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2006, 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [10] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::default_random_engine a; + a.discard(9999); + + // This is our choice for now. + std::minstd_rand0 b; + b.discard(9999); + + assert( a() == b() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_copy.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_copy.cc new file mode 100644 index 00000000000..ab6fb091f0c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_copy.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::subtract_with_carry_engine<long, 24, 10, 24> + base_engine; + + base_engine b; + + std::discard_block_engine<base_engine, 389, 24> e(b); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_move.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_move.cc new file mode 100644 index 00000000000..0d8e361a4a5 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/base_move.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::subtract_with_carry_engine<long, 24, 10, 24> + base_engine; + + std::discard_block_engine<base_engine, 389, 24> + e(std::move(base_engine())); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/default.cc new file mode 100644 index 00000000000..cc039b81aac --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::discard_block_engine + < + std::subtract_with_carry_engine<long, 24, 10, 24>, + 389, 24 + > e; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed1.cc new file mode 100644 index 00000000000..6401cc7ffaf --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed1.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + unsigned long seed = 2; + + std::discard_block_engine + < + std::subtract_with_carry_engine<long, 24, 10, 24>, + 389, 24 + > e(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed2.cc new file mode 100644 index 00000000000..c841d64c9d7 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed2.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + double seed = 2.0; + + std::discard_block_engine + < + std::subtract_with_carry_engine<long, 24, 10, 24>, + 389, 24 + > e(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq.cc new file mode 100644 index 00000000000..182ba1a8833 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::seed_seq seq; + + std::discard_block_engine + < + std::subtract_with_carry_engine<long, 24, 10, 24>, + 389, 24 + > e(seq); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/equal.cc new file mode 100644 index 00000000000..ea906f97112 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/equal.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::discard_block_engine + < + std::subtract_with_carry_engine<long, 24, 10, 24>, + 389, 24 + > u, v; + + VERIFY( u == v ); + + u.discard(100); + v.discard(100); + + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc new file mode 100644 index 00000000000..84a8d5db70e --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/operators/serialize.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::discard_block_engine + < + std::subtract_with_carry_engine<long, 24, 10, 24>, + 389, 24 + > u, v; + + u(); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/requirements/typedefs.cc new file mode 100644 index 00000000000..67c2d730fad --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/requirements/typedefs.cc @@ -0,0 +1,39 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 Class template discard_blockl_engine [rand.adapt.disc] +// 26.4.2.3 Concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> + +void +test01() +{ + typedef std::discard_block_engine + < + std::subtract_with_carry_engine<long, 24, 10, 24>, + 389, 24 + > test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/default.cc new file mode 100644 index 00000000000..93cd47b0ac3 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/default.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::discrete_distribution<> u; + std::vector<double> probablility = u.probabilities(); + VERIFY( probablility.size() == 1 ); + VERIFY( probablility[0] == 1.0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/initlist.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/initlist.cc new file mode 100644 index 00000000000..6ddaad98397 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/initlist.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::discrete_distribution<> u({0.0, 2.0, 4.0, 3.0, 4.0, 0.0}); + std::vector<double> probablility = u.probabilities(); + VERIFY( probablility.size() == 6 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/num_xbound_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/num_xbound_fun.cc new file mode 100644 index 00000000000..0dbe52a52a9 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/num_xbound_fun.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <cmath> +#include <testsuite_hooks.h> + +struct cosine_distribution +{ + cosine_distribution(double x0, double lambda) + : _M_x0(x0), _M_lambda(lambda) + { } + + double + operator()(double x) + { + if (x - _M_x0 < -_M_lambda / 4) + return 0.0; + else if (x - _M_x0 > _M_lambda / 4) + return 0.0; + else + return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda); + } + +private: + double _M_x0; + double _M_lambda; +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + cosine_distribution cd(1.5, 3.0); + std::discrete_distribution<> u(21, -10.0, 10.0, cd); + std::vector<double> probablility = u.probabilities(); + VERIFY( probablility.size() == 21 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc new file mode 100644 index 00000000000..cf0f0d9296d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/cons/range.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5}; + std::discrete_distribution<> u(wt.begin(), wt.end()); + std::vector<double> probablility = u.probabilities(); + VERIFY( probablility.size() == 5 ); + VERIFY( probablility[0] == 0.5 / 6.0 ); + VERIFY( probablility[2] == 2.5 / 6.0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/serialize.cc new file mode 100644 index 00000000000..3bd6f6cd12f --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/operators/serialize.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5}; + std::discrete_distribution<int> u(wt.begin(), wt.end()), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..877952aa2cc --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/discrete_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.1 Class template discrete_distribution [rand.dist.samp.discrete] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::discrete_distribution<> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/default.cc new file mode 100644 index 00000000000..2935bdae4d4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::exponential_distribution<> u; + VERIFY( u.lambda() == 1.0 ); + typedef std::exponential_distribution<>::result_type result_type; + VERIFY( u.min() == 0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/parms.cc new file mode 100644 index 00000000000..c3b893ced7a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::exponential_distribution<> u(0.5); + VERIFY( u.lambda() == 0.5 ); + typedef std::exponential_distribution<>::result_type result_type; + VERIFY( u.min() == 0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/operators/serialize.cc new file mode 100644 index 00000000000..9645931f519 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::exponential_distribution<double> u(0.5), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..ce271962f25 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/exponential_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.2 Class template exponential_distribution [rand.dist.pois.exp] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::exponential_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/default.cc new file mode 100644 index 00000000000..e4378c9bd96 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::extreme_value_distribution<> u; + VERIFY( u.a() == 0.0 ); + VERIFY( u.b() == 1.0 ); + typedef std::extreme_value_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/parms.cc new file mode 100644 index 00000000000..1e54492b124 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::extreme_value_distribution<> u(5.0, 2.0); + VERIFY( u.a() == 5.0 ); + VERIFY( u.b() == 2.0 ); + typedef std::extreme_value_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/operators/serialize.cc new file mode 100644 index 00000000000..c07cdfc1ab8 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::extreme_value_distribution<double> u, v(5.0, 2.0); + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..e87436f2bec --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/extreme_value_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.5 Class template extreme_value_distribution [rand.dist.pois.extreme] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::extreme_value_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/default.cc new file mode 100644 index 00000000000..e7accb3a378 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::fisher_f_distribution<> u; + VERIFY( u.m() == 1.0 ); + VERIFY( u.n() == 1.0 ); + typedef std::fisher_f_distribution<>::result_type result_type; + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/parms.cc new file mode 100644 index 00000000000..5c02b82d444 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::fisher_f_distribution<> u(2.0, 3.0); + VERIFY( u.m() == 2.0 ); + VERIFY( u.n() == 3.0 ); + typedef std::fisher_f_distribution<>::result_type result_type; + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/operators/serialize.cc new file mode 100644 index 00000000000..6cb024972c5 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::fisher_f_distribution<double> u(2.0, 3.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..207dfd58ac9 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/fisher_f_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.5 Class template fisher_f_distribution [rand.dist.norm.f] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::fisher_f_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/default.cc new file mode 100644 index 00000000000..74be9d18960 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::gamma_distribution<> u; + VERIFY( u.alpha() == 1.0 ); + VERIFY( u.beta() == 1.0 ); + VERIFY( u.min() == 0.0 ); + typedef std::gamma_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/parms.cc new file mode 100644 index 00000000000..1dd7a76a5dc --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::gamma_distribution<> u(1.5, 3.0); + VERIFY( u.alpha() == 1.5 ); + VERIFY( u.beta() == 3.0 ); + VERIFY( u.min() == 0.0 ); + typedef std::gamma_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/operators/serialize.cc new file mode 100644 index 00000000000..b99e0c24e42 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::gamma_distribution<double> u(1.5, 3.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..b3c6b4eeafa --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/gamma_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.3 Class template gamma_distribution [rand.dist.pois.gamma] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::gamma_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/default.cc new file mode 100644 index 00000000000..e248f7f0ce6 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geo] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::geometric_distribution<> u; + VERIFY( u.p() == 0.5 ); + VERIFY( u.min() == 0 ); + typedef std::geometric_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/parms.cc new file mode 100644 index 00000000000..aa158a32ac1 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geo] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::geometric_distribution<> u(0.75); + VERIFY( u.p() == 0.75 ); + VERIFY( u.min() == 0 ); + typedef std::geometric_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/operators/serialize.cc new file mode 100644 index 00000000000..e2fbdaa29a4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geom] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::geometric_distribution<int> u(0.75), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..7cac29a40e2 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/geometric_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.3 Class template geometric_distribution [rand.dist.bern.geom] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::geometric_distribution<int> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_copy.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_copy.cc new file mode 100644 index 00000000000..efaa94b2f64 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_copy.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> + base_engine; + + base_engine b; + + std::independent_bits_engine<base_engine, 48, unsigned long> e(b); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_move.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_move.cc new file mode 100644 index 00000000000..8adcecd25ef --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/base_move.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> + base_engine; + + std::independent_bits_engine<base_engine, 48, unsigned long> + e(std::move(base_engine())); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/default.cc new file mode 100644 index 00000000000..2ccd4e8d557 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::independent_bits_engine + < + std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>, + 48, + unsigned long + > e; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed1.cc new file mode 100644 index 00000000000..e774b760c9c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed1.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + unsigned long seed = 2; + + std::independent_bits_engine + < + std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>, + 48, + unsigned long + > e(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed2.cc new file mode 100644 index 00000000000..e4362d6165d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed2.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + double seed = 2.0; + + std::independent_bits_engine + < + std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>, + 48, + unsigned long + > e(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq.cc new file mode 100644 index 00000000000..628af20b96f --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::seed_seq seq; + + std::independent_bits_engine + < + std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>, + 48, + unsigned long + > e(seq); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/equal.cc new file mode 100644 index 00000000000..6147cf0d5ac --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/equal.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::independent_bits_engine + <std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>, + 48, unsigned long> u, v; + + VERIFY( u == v ); + + u.discard(100); + v.discard(100); + + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc new file mode 100644 index 00000000000..a92553e10cd --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/operators/serialize.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::independent_bits_engine + <std::subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>, + 48, unsigned long> u, v; + + u(); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/requirements/typedefs.cc new file mode 100644 index 00000000000..f268e9ad808 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/requirements/typedefs.cc @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.2 class template independent_bits_engine [rand.adapt.ibits] +// 26.4.2.3 Concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> + +void +test01() +{ + typedef std::independent_bits_engine + < + std::subtract_with_carry_engine + < + uint_fast64_t, 48, 5, 12 + >, + 48, unsigned long + > test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/knuth_b.cc b/libstdc++-v3/testsuite/26_numerics/random/knuth_b.cc new file mode 100644 index 00000000000..5f835769efb --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/knuth_b.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2006, 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [9] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::knuth_b a; + a.discard(9999); + + VERIFY( a() == 1112339016 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/default.cc new file mode 100644 index 00000000000..1136785e9a3 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/default.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::linear_congruential_engine<unsigned long, 48271, 0, 2147483647> x; + VERIFY( x.min() == 1 ); + VERIFY( x.max() == 2147483647-1 ); + VERIFY( x() == 48271 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed1.cc new file mode 100644 index 00000000000..9d2e21b54c7 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed1.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + unsigned long seed = 2; + std::linear_congruential_engine<unsigned long, 48271, 0, 2147483647> x(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed2.cc new file mode 100644 index 00000000000..5f446773ecc --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed2.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + double seed = 2.0; + std::linear_congruential_engine<unsigned long, 48271, 0, 2147483647> x(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/equal.cc new file mode 100644 index 00000000000..02f1f5a9708 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/equal.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::minstd_rand0 a; + std::minstd_rand0 b; + std::minstd_rand0 c(120); + + VERIFY( a == b ); + VERIFY( !(a == c) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc new file mode 100644 index 00000000000..6256cadc68d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/operators/serialize.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::minstd_rand0 a; + std::minstd_rand0 b; + + a(); // advance + str << a; + VERIFY( !(a == b) ); + + str >> b; + VERIFY( a == b ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/non_uint_neg.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/non_uint_neg.cc new file mode 100644 index 00000000000..4c83a97adfd --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/non_uint_neg.cc @@ -0,0 +1,33 @@ +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// { dg-do compile } +// { dg-options "-std=c++0x -D_GLIBCXX_CONCEPT_CHECKS" } +// { dg-error "not a valid type" "" { target *-*-* } 32 } +// { dg-error "invalid type" "" { target *-*-* } 32 } + +// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> + +std::linear_congruential_engine<double, 48271, 0, 2147483647> x; + diff --git a/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/typedefs.cc new file mode 100644 index 00000000000..5c9b8ad6abb --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.1 class template linear_congruential_engine [rand.eng.lcong] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> + +void +test01() +{ + typedef std::linear_congruential_engine<unsigned long, 2, 0, 4> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/default.cc new file mode 100644 index 00000000000..4fe1dda5213 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::lognormal_distribution<> u; + VERIFY( u.m() == 0.0 ); + VERIFY( u.s() == 1.0 ); + typedef std::lognormal_distribution<>::result_type result_type; + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/parms.cc new file mode 100644 index 00000000000..42fe3ac3816 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::lognormal_distribution<> u(5.0, 2.0); + VERIFY( u.m() == 5.0 ); + VERIFY( u.s() == 2.0 ); + typedef std::lognormal_distribution<>::result_type result_type; + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/operators/serialize.cc new file mode 100644 index 00000000000..3626cfbb424 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::lognormal_distribution<double> u(5.0, 2.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..c1260aa604a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/lognormal_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.2 Class template lognormal_distribution [rand.dist.norm.lognormal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::lognormal_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc new file mode 100644 index 00000000000..e335b82217b --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/default.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + typedef unsigned long value_type; + + std::mersenne_twister_engine< + value_type, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> x; + + VERIFY( x.min() == 0 ); + // XXX VERIFY( x.max() == 4294967295ul); + VERIFY( x() == 3499211612ul ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed1.cc new file mode 100644 index 00000000000..a5e0489fefa --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed1.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + unsigned long seed = 2; + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> x(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed2.cc new file mode 100644 index 00000000000..954f27360f4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed2.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + double seed = 2.0; + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> x(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/equal.cc new file mode 100644 index 00000000000..1e7b4d9941c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/equal.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> u, v; + + VERIFY( u == v ); + + u.discard(100); + v.discard(100); + + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc new file mode 100644 index 00000000000..90f51d6cbf2 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/operators/serialize.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <sstream> +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::mersenne_twister_engine< + unsigned long, 32, 624, 397, 31, + 0x9908b0dful, 11, + 0xfffffffful, 7, + 0x9d2c5680ul, 15, + 0xefc60000ul, 18, 1812433253ul> u, v; + + u(); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/requirements/typedefs.cc new file mode 100644 index 00000000000..e94bd08a352 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/requirements/typedefs.cc @@ -0,0 +1,40 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.2 Class template mersenne_twister_engine [rand.eng.mers] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> + +void +test01() +{ + typedef std::mersenne_twister_engine<unsigned long, + 32, 624, 397, 31, + 0x9908b0df, 11, + 0xfffffffful, 7, + 0x9d2c5680, 15, + 0xefc60000, 18, 1812433253ul> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/minstd_rand.cc b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand.cc new file mode 100644 index 00000000000..c8118a3bedf --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2006, 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines with predefined parameters +// 26.4.5 [2] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::minstd_rand a; + a.discard(9999); + + VERIFY( a() == 399268537 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/minstd_rand0.cc b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand0.cc new file mode 100644 index 00000000000..045f1f97b5e --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/minstd_rand0.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [1] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::minstd_rand0 a; + a.discard(9999); + + VERIFY( a() == 1043618065 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mt19937.cc b/libstdc++-v3/testsuite/26_numerics/random/mt19937.cc new file mode 100644 index 00000000000..81e2f086efb --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mt19937.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2006, 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [3] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::mt19937 a; + a.discard(9999); + + VERIFY( a() == 4123659995ul ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/mt19937_64.cc b/libstdc++-v3/testsuite/26_numerics/random/mt19937_64.cc new file mode 100644 index 00000000000..2ec8a54ce5e --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/mt19937_64.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2006, 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [4] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::mt19937_64 a; + a.discard(9999); + + VERIFY( a() == 9981545732273789042ul ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/default.cc new file mode 100644 index 00000000000..280a9d7833e --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::negative_binomial_distribution<> u; + VERIFY( u.k() == 1 ); + VERIFY( u.p() == 0.5 ); + typedef std::negative_binomial_distribution<>::result_type result_type; + VERIFY( u.min() == 0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/parms.cc new file mode 100644 index 00000000000..0c2f66d5d95 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::negative_binomial_distribution<> u(3, 0.75); + VERIFY( u.k() == 3 ); + VERIFY( u.p() == 0.75 ); + typedef std::negative_binomial_distribution<>::result_type result_type; + VERIFY( u.min() == 0 ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/serialize.cc new file mode 100644 index 00000000000..1817d731afe --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::negative_binomial_distribution<int> u(3, 0.75), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..b5888c426c8 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/negative_binomial_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.2.4 Class template negative_binomial_distribution [rand.dist.bern.negbin] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::negative_binomial_distribution<int> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/default.cc new file mode 100644 index 00000000000..1c6ee51a172 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::normal_distribution<> u; + VERIFY( u.mean() == 0.0 ); + VERIFY( u.stddev() == 1.0 ); + typedef std::normal_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/parms.cc new file mode 100644 index 00000000000..41bf9c44ffc --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::normal_distribution<> u(5.0, 2.0); + VERIFY( u.mean() == 5.0 ); + VERIFY( u.stddev() == 2.0 ); + typedef std::normal_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc new file mode 100644 index 00000000000..fdf90ca525d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::normal_distribution<double> u(5.0, 2.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..d22ad223a54 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/normal_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.1 Class template normal_distribution [rand.dist.norm.normal] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::normal_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/default.cc new file mode 100644 index 00000000000..f5e9506d0f4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/default.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::piecewise_constant_distribution<> u; + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 2 ); + VERIFY( interval[0] == 0.0 ); + VERIFY( interval[1] == 1.0 ); + VERIFY( density.size() == 1 ); + VERIFY( density[0] == 1.0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/initlist_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/initlist_fun.cc new file mode 100644 index 00000000000..22bf5b2c438 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/initlist_fun.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <cmath> +#include <testsuite_hooks.h> + +struct cosine_distribution +{ + cosine_distribution(double x0, double lambda) + : _M_x0(x0), _M_lambda(lambda) + { } + + double + operator()(double x) + { + if (x - _M_x0 < -_M_lambda / 4) + return 0.0; + else if (x - _M_x0 > _M_lambda / 4) + return 0.0; + else + return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda); + } + +private: + double _M_x0; + double _M_lambda; +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + cosine_distribution cd(1.5, 3.0); + std::piecewise_constant_distribution<> u({-10.0, -8.0, -6.0, -4.0, -2.0, + 0.0, 2.0, 4.0, 6.0, 8.0, 10.0}, + cd); + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 11 ); + VERIFY( density.size() == 10 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/num_xbound_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/num_xbound_fun.cc new file mode 100644 index 00000000000..ff900a64049 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/num_xbound_fun.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <cmath> +#include <testsuite_hooks.h> + +struct cosine_distribution +{ + cosine_distribution(double x0, double lambda) + : _M_x0(x0), _M_lambda(lambda) + { } + + double + operator()(double x) + { + if (x - _M_x0 < -_M_lambda / 4) + return 0.0; + else if (x - _M_x0 > _M_lambda / 4) + return 0.0; + else + return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda); + } + +private: + double _M_x0; + double _M_lambda; +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + cosine_distribution cd(1.5, 3.0); + std::piecewise_constant_distribution<> u(21, -10.0, 10.0, cd); + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 22 ); + VERIFY( density.size() == 21 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc new file mode 100644 index 00000000000..5e2ee1024fa --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; + std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5}; + std::piecewise_constant_distribution<> u(x.begin(), x.end(), wt.begin()); + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 6 ); + VERIFY( interval[0] == 0.0 ); + VERIFY( interval[5] == 5.0 ); + VERIFY( density.size() == 5 ); + VERIFY( density[0] == 0.5 / 6.0 ); + VERIFY( density[2] == 2.5 / 6.0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize.cc new file mode 100644 index 00000000000..28b2fb3333d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/operators/serialize.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; + std::vector<double> wt = {0.5, 1.0, 2.5, 1.5, 0.5}; + std::piecewise_constant_distribution<double> + u(x.begin(), x.end(), wt.begin()), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..523261e488c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_constant_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::piecewise_constant_distribution<> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/default.cc new file mode 100644 index 00000000000..41c5e484a35 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/default.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::piecewise_linear_distribution<> u; + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 2 ); + VERIFY( interval[0] == 0.0 ); + VERIFY( interval[1] == 1.0 ); + VERIFY( density.size() == 2 ); + VERIFY( density[0] == 1.0 ); + VERIFY( density[1] == 1.0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/initlist_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/initlist_fun.cc new file mode 100644 index 00000000000..91db760cef7 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/initlist_fun.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <cmath> +#include <testsuite_hooks.h> + +struct cosine_distribution +{ + cosine_distribution(double x0, double lambda) + : _M_x0(x0), _M_lambda(lambda) + { } + + double + operator()(double x) + { + if (x - _M_x0 < -_M_lambda / 4) + return 0.0; + else if (x - _M_x0 > _M_lambda / 4) + return 0.0; + else + return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda); + } + +private: + double _M_x0; + double _M_lambda; +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + cosine_distribution cd(1.5, 3.0); + std::piecewise_linear_distribution<> u({-10.0, -8.0, -6.0, -4.0, -2.0, + 0.0, 2.0, 4.0, 6.0, 8.0, 10.0}, + cd); + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 11 ); + VERIFY( density.size() == 11 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/num_xbound_fun.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/num_xbound_fun.cc new file mode 100644 index 00000000000..187601b8a41 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/num_xbound_fun.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <cmath> +#include <testsuite_hooks.h> + +struct cosine_distribution +{ + cosine_distribution(double x0, double lambda) + : _M_x0(x0), _M_lambda(lambda) + { } + + double + operator()(double x) + { + if (x - _M_x0 < -_M_lambda / 4) + return 0.0; + else if (x - _M_x0 > _M_lambda / 4) + return 0.0; + else + return std::cos(2 * M_PI * (x - _M_x0) / _M_lambda); + } + +private: + double _M_x0; + double _M_lambda; +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + cosine_distribution cd(1.5, 3.0); + std::piecewise_linear_distribution<> u(21, -10.0, 10.0, cd); + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 22 ); + VERIFY( density.size() == 22 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc new file mode 100644 index 00000000000..1e0dbbc824a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; + std::vector<double> wt = {0.0, 1.0, 2.5, 1.5, 3.5, 0.0}; + std::piecewise_linear_distribution<> u(x.begin(), x.end(), wt.begin()); + std::vector<double> interval = u.intervals(); + std::vector<double> density = u.densities(); + VERIFY( interval.size() == 6 ); + VERIFY( interval[0] == 0.0 ); + VERIFY( interval[5] == 5.0 ); + VERIFY( density.size() == 6 ); + VERIFY( density[0] == 0.0 ); + VERIFY( density[4] == 3.5 / 8.5 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize.cc new file mode 100644 index 00000000000..c38d47a5d31 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/serialize.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::vector<double> x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; + std::vector<double> wt = {0.0, 1.0, 2.5, 1.5, 0.5, 0.0}; + std::piecewise_linear_distribution<double> + u(x.begin(), x.end(), wt.begin()), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..71f80df8024 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-12-03 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.5.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::piecewise_linear_distribution<> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/default.cc new file mode 100644 index 00000000000..bf6c7532877 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::poisson_distribution<> u; + VERIFY( u.mean() == 1.0 ); + VERIFY( u.min() == 0 ); + typedef std::poisson_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/parms.cc new file mode 100644 index 00000000000..b498a2e58d3 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::poisson_distribution<> u(5.0); + VERIFY( u.mean() == 5.0 ); + VERIFY( u.min() == 0 ); + typedef std::poisson_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/serialize.cc new file mode 100644 index 00000000000..79511024885 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::poisson_distribution<int> u(5.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..125a9067acc --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/poisson_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.1 Class template poisson_distribution [rand.dist.pois.poisson] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::poisson_distribution<int> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc new file mode 100644 index 00000000000..e162038a90b --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.6 class random_device [rand.device] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::random_device x; + + VERIFY( x.min() == std::numeric_limits<std::random_device::result_type>::min() ); + VERIFY( x.max() == std::numeric_limits<std::random_device::result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc new file mode 100644 index 00000000000..ec5e16f004b --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.6 class random_device [rand.device] +// 26.4.6 [3] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + +#ifdef _GLIBCXX_USE_RANDOM_TR1 + std::random_device x("/dev/random"); +#else + std::random_device x("0"); +#endif + + VERIFY( x.min() == std::numeric_limits<std::random_device::result_type>::min() ); + VERIFY( x.max() == std::numeric_limits<std::random_device::result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/requirements/typedefs.cc new file mode 100644 index 00000000000..0ebf1aa551c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/requirements/typedefs.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.6 class random_device [rand.device] + +#include <random> + +void +test01() +{ + typedef std::random_device test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux24.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux24.cc new file mode 100644 index 00000000000..7b20eb36c3b --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux24.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [7] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ranlux24 a; + a.discard(9999); + + VERIFY( a() == 9901578ul ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux24_base.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux24_base.cc new file mode 100644 index 00000000000..5298858f95e --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux24_base.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [5] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ranlux24_base a; + a.discard(9999); + + VERIFY( a() == 7937952ul ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux48.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux48.cc new file mode 100644 index 00000000000..57b07205b94 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux48.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [8] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ranlux48 a; + a.discard(9999); + + VERIFY( a() == 249142670248501ull ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/ranlux48_base.cc b/libstdc++-v3/testsuite/26_numerics/random/ranlux48_base.cc new file mode 100644 index 00000000000..c5b1ef64c0d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/ranlux48_base.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-18 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef] +// 26.4.5 [6] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ranlux48_base a; + a.discard(9999); + + VERIFY( a() == 61839128582725ull ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc new file mode 100644 index 00000000000..7bbfdc30420 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.7.1 Class seed_seq [rand.util.seedseq] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + std::seed_seq seq; + + std::vector<unsigned> foo(10000); + seq.generate(foo.begin(), foo.end()); + + VERIFY( seq.size() == 0 ); + //VERIFY(); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc new file mode 100644 index 00000000000..4bfa217c181 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/initlist.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2009-02-13 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.7.1 Class seed_seq [rand.util.seedseq] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::seed_seq seq({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + std::vector<unsigned> foo(10000); + seq.generate(foo.begin(), foo.end()); + + VERIFY( seq.size() == 10 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/range.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/range.cc new file mode 100644 index 00000000000..c5eda5dbcc9 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/cons/range.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.7.1 Class seed_seq [rand.util.seedseq] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + unsigned in[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::seed_seq seq(in, in + 10); + + std::vector<unsigned> foo(10000); + seq.generate(foo.begin(), foo.end()); + + VERIFY( seq.size() == 10 ); + //VERIFY(); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc new file mode 100644 index 00000000000..90455607149 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/seed_seq/requirements/typedefs.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-12-05 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.7.1 Class seed_seq [rand.util.seedseq] + +#include <random> + +void +test01() +{ + typedef std::seed_seq test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_copy.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_copy.cc new file mode 100644 index 00000000000..a2659dd468c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_copy.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::linear_congruential_engine + <uint_fast32_t, 16807UL, 0UL, 2147483647UL> base_engine; + + base_engine b; + + std::shuffle_order_engine<base_engine, 256> e(b); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_move.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_move.cc new file mode 100644 index 00000000000..4e8c7af3d31 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/base_move.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::linear_congruential_engine + <uint_fast32_t, 16807UL, 0UL, 2147483647UL> base_engine; + + std::shuffle_order_engine<base_engine, 256> + e(std::move(base_engine())); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/default.cc new file mode 100644 index 00000000000..a33a6551c93 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::shuffle_order_engine + < + std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>, + 256 + > e; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed1.cc new file mode 100644 index 00000000000..0df9c55cbf3 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed1.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + unsigned long seed = 2; + + std::shuffle_order_engine + < + std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>, + 256 + > e(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed2.cc new file mode 100644 index 00000000000..c492d0a30a3 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed2.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + double seed = 2.0; + + std::shuffle_order_engine + < + std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>, + 256 + > e(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq.cc new file mode 100644 index 00000000000..80c425b3dcf --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=c++0x" } +// +// 2008-12-07 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::seed_seq seq; + + std::shuffle_order_engine + < + std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>, + 256 + > e(seq); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/equal.cc new file mode 100644 index 00000000000..3b5cebb5853 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/equal.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::shuffle_order_engine + < + std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>, + 256 + > u, v; + + VERIFY( u == v ); + + u.discard(100); + v.discard(100); + + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc new file mode 100644 index 00000000000..afaa4051468 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/operators/serialize.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.1 class template discard_block_engine [rand.adapt.disc] +// 26.4.2.3 concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::shuffle_order_engine + < + std::linear_congruential_engine<uint_fast32_t,16807UL, 0UL, 2147483647UL>, + 256 + > u, v; + + u(); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/requirements/typedefs.cc new file mode 100644 index 00000000000..605a10089ce --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/requirements/typedefs.cc @@ -0,0 +1,41 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.4.3 class template shuffle_order_engine [rand.adapt.shuf] +// 26.4.2.3 Concept RandomNumberEngineAdaptor [rand.concept.adapt] + +#include <random> + +void +test01() +{ + typedef std::shuffle_order_engine + < + std::linear_congruential_engine + < + uint_fast32_t,16807UL, 0UL, 2147483647UL + >, + 256 + > test_type; + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/default.cc new file mode 100644 index 00000000000..5f0169b739d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::student_t_distribution<> u; + VERIFY( u.n() == 1.0 ); + typedef std::student_t_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/parms.cc new file mode 100644 index 00000000000..4d6aa6149e5 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::student_t_distribution<> u(1.5); + VERIFY( u.n() == 1.5 ); + typedef std::student_t_distribution<>::result_type result_type; + VERIFY( u.min() == std::numeric_limits<result_type>::min() ); + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/operators/serialize.cc new file mode 100644 index 00000000000..ab3a9bb6112 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::student_t_distribution<double> u(1.5), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..3380873cd63 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/student_t_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.4.6 Class template student_t_distribution [rand.dist.norm.t] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::student_t_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/default.cc new file mode 100644 index 00000000000..8d841074f5b --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/default.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::subtract_with_carry_engine<unsigned long, 24, 10, 24> x; + VERIFY( x.min() == 0 ); + VERIFY( x.max() == ((1UL << 24) - 1) ); + VERIFY( x() == 15039276 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed1.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed1.cc new file mode 100644 index 00000000000..e26261a1219 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed1.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + unsigned long seed = 2; + std::subtract_with_carry_engine<unsigned long, 24, 10, 24> x(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed2.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed2.cc new file mode 100644 index 00000000000..8b96c16b43d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed2.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + double seed = 2.0; + std::subtract_with_carry_engine<unsigned long, 24, 10, 24> x(seed); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/equal.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/equal.cc new file mode 100644 index 00000000000..9dbed3c4653 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/equal.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::subtract_with_carry_engine<unsigned long, 24, 10, 24> u; + std::subtract_with_carry_engine<unsigned long, 24, 10, 24> v; + + VERIFY( u == v ); + + u.discard(100); + v.discard(100); + + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc new file mode 100644 index 00000000000..e6705e43aef --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub] +// 26.4.2.2 Concept RandomNumberEngine [rand.concept.eng] + +#include <sstream> +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::subtract_with_carry_engine<unsigned long, 24, 10, 24> u; + std::subtract_with_carry_engine<unsigned long, 24, 10, 24> v; + + u(); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/requirements/typedefs.cc new file mode 100644 index 00000000000..2cd922f1c60 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/requirements/typedefs.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.3.3 Class template subtract_with_carry_engine [rand.eng.sub] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::subtract_with_carry_engine<unsigned long, 24, 10, 24> + test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc new file mode 100644 index 00000000000..db5c653e923 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist.uni.int] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::uniform_int_distribution<int> u; + VERIFY( u.a() == 0 ); + VERIFY( u.b() == 9 ); + VERIFY( u.min() == 0 ); + VERIFY( u.max() == 9 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms.cc new file mode 100644 index 00000000000..3e4f4858d98 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::uniform_int_distribution<int> u(1, 20); + VERIFY( u.a() == 1 ); + VERIFY( u.b() == 20 ); + VERIFY( u.min() == 1 ); + VERIFY( u.max() == 20 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms_neg.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms_neg.cc new file mode 100644 index 00000000000..129cc25d0c6 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/parms_neg.cc @@ -0,0 +1,41 @@ +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// { dg-do run { xfail *-*-* } } +// { dg-options "-std=c++0x -D_GLIBCXX_DEBUG" } + +// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + std::uniform_int_distribution<int> u(20, 1); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/serialize.cc new file mode 100644 index 00000000000..486bdb4ea9b --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::uniform_int_distribution<int> u(1, 20), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..2074c12d03a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.1 Class template uniform_int_distribution [rand.dist_uni] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::uniform_int_distribution<int> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/default.cc new file mode 100644 index 00000000000..944fe827751 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/default.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.1 Class template uniform_real_distribution [rand.dist.uni.real] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::uniform_real_distribution<double> u; + VERIFY( u.a() == 0.0 ); + VERIFY( u.b() == 1.0 ); + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == 1.0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms.cc new file mode 100644 index 00000000000..cbfbd41b8b1 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.1 Class template uniform_real_distribution [rand.dist_uni] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::uniform_real_distribution<double> u(-5.0, 5.0); + VERIFY( u.a() == -5.0 ); + VERIFY( u.b() == 5.0 ); + VERIFY( u.min() == -5.0 ); + VERIFY( u.max() == 5.0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms_neg.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms_neg.cc new file mode 100644 index 00000000000..930f9de1464 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/cons/parms_neg.cc @@ -0,0 +1,41 @@ +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// { dg-do run { xfail *-*-* } } +// { dg-options "-std=c++0x -D_GLIBCXX_DEBUG" } + +// 26.4.8.1.1 Class template uniform_real_distribution [rand.dist_uni] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + std::uniform_real_distribution<double> u(5.0, 0.0); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/serialize.cc new file mode 100644 index 00000000000..3fbc584307d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.2 Class template uniform_real_distribution [rand.dist.uni.real] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::uniform_real_distribution<double> u(-5.0, 5.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..696e20b601a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_real_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.1.2 Class template uniform_real_distribution [rand.dist.uni.real] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::uniform_real_distribution<double> test_type; + + typedef test_type::result_type result_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/default.cc new file mode 100644 index 00000000000..6867c117a62 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/default.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::weibull_distribution<> u; + VERIFY( u.a() == 1.0 ); + VERIFY( u.b() == 1.0 ); + VERIFY( u.min() == 0.0 ); + typedef std::weibull_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/parms.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/parms.cc new file mode 100644 index 00000000000..3eec8c6489d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/cons/parms.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::weibull_distribution<> u(2.0, 3.5); + VERIFY( u.a() == 2.0 ); + VERIFY( u.b() == 3.5 ); + VERIFY( u.min() == 0.0 ); + typedef std::weibull_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits<result_type>::max() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/operators/serialize.cc new file mode 100644 index 00000000000..bf548d3feb6 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/operators/serialize.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + std::weibull_distribution<double> u(2.0, 3.5), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + VERIFY( !(u == v) ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..acdea1d22b1 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/weibull_distribution/requirements/typedefs.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } +// +// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 26.4.8.3.4 Class template weibull_distribution [rand.dist.pois.weibull] +// 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] + +#include <random> + +void +test01() +{ + typedef std::weibull_distribution<double> test_type; + + typedef test_type::result_type result_type; +} |