random: Trivial uglification fixes.

2006-06-06  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/random: Trivial uglification fixes.
	* include/tr1/random.tcc: Likewise.

	* include/tr1/random (subtract_with_carry<>::
	subtract_with_carry(_IntType)): Fix parameter type to unsigned long.
	(subtract_with_carry<>::seed(_IntType)): Likewise.
	* include/tr1/random.tcc (subtract_with_carry<>::seed(_IntType)):
	Adjust.

From-SVN: r114440
This commit is contained in:
Paolo Carlini 2006-06-06 17:37:33 +00:00 committed by Paolo Carlini
parent 8cf0db2bcd
commit 281864aaf7
3 changed files with 378 additions and 349 deletions

View File

@ -1,3 +1,14 @@
2006-06-06 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random: Trivial uglification fixes.
* include/tr1/random.tcc: Likewise.
* include/tr1/random (subtract_with_carry<>::
subtract_with_carry(_IntType)): Fix parameter type to unsigned long.
(subtract_with_carry<>::seed(_IntType)): Likewise.
* include/tr1/random.tcc (subtract_with_carry<>::seed(_IntType)):
Adjust.
2006-06-05 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (mersenne_twister<>::seed()): Fix per

View File

@ -62,17 +62,17 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
*/
namespace _Private
{
// Type selectors -- are these already implemeted elsewhere?
// Type selectors -- are these already implemented elsewhere?
template<bool, typename _TpTrue, typename _TpFalse>
struct _Select
{
typedef _TpTrue Type;
typedef _TpTrue _Type;
};
template<typename _TpTrue, typename _TpFalse>
struct _Select<false, _TpTrue, _TpFalse>
{
typedef _TpFalse Type;
typedef _TpFalse _Type;
};
/*
@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
};
/*
* Converts a value generated by the adapted random number genereator into a
* 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
@ -154,10 +154,10 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
public:
/**
* Constructs a variate generator with the uniform random number
* generator @p eng for the random distribution @p d.
* generator @p __eng for the random distribution @p __dist.
*
* @throws Any exceptions which may thrown by the copy constructors of the
* @p _Generator or @p _Dist objects.
* @throws Any exceptions which may thrown by the copy constructors of
* the @p _Generator or @p _Dist objects.
*/
variate_generator(engine_type __eng, distribution_type __dist)
: _M_engine(__eng), _M_dist(__dist) { }
@ -269,66 +269,67 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* 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 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>
template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
class linear_congruential
{
__glibcxx_class_requires(UIntType, _UnsignedIntegerConcept)
// __glibcpp_class_requires(a < m && c < m)
__glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
// __glibcpp_class_requires(__a < __m && __c < __m)
public:
/** The type of the generated random value. */
typedef UIntType result_type;
typedef _UIntType result_type;
/** The multiplier. */
static const UIntType multiplier = a;
static const _UIntType multiplier = __a;
/** An increment. */
static const UIntType increment = c;
static const _UIntType increment = __c;
/** The modulus. */
static const UIntType modulus = m;
static const _UIntType modulus = __m;
/**
* Constructs a %linear_congruential random number generator engine with
* seed @p s. The default seed value is 1.
* seed @p __s. The default seed value is 1.
*
* @param s The initial seed value.
* @param __s The initial seed value.
*/
explicit linear_congruential(unsigned long s = 1);
explicit linear_congruential(unsigned long __s = 1);
/**
* Constructs a %linear_congruential random number generator engine
* seeded from the generator function @g.
* seeded from the generator function @p __g.
*
* @param g The seed generator function.
* @param __g The seed generator function.
*/
template<class Gen>
linear_congruential(Gen& g);
template<class _Gen>
linear_congruential(_Gen& __g);
/**
* Resets the %linear_congruential random number generator engine sequence
* to @p.
* Reseeds the %linear_congruential random number generator engine
* sequence to the seed @g __s.
*
* @param s The new seed.
* @param __s The new seed.
*/
void
seed(unsigned long s = 1);
seed(unsigned long __s = 1);
/**
* Resets the %linear_congruential random number generator engine sequence
* using a vlaue from the generator function @g.
* Reseeds the %linear_congruential random number generator engine
* sequence using values from the generator function @p __g.
*
* @param g the seed generator function.
* @param __g the seed generator function.
*/
template<class Gen>
template<class _Gen>
void
seed(Gen& g)
{ seed(g, typename is_fundamental<Gen>::type()); }
seed(_Gen& __g)
{ seed(__g, typename is_fundamental<_Gen>::type()); }
/**
* Gets the smallest possible value in the output range.
@ -352,72 +353,74 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* 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.
* @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; }
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 object.
* @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); }
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.
* 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.
* @param __os The output stream.
* @param __lcr A linear_congruential random number generator.
* @returns __os.
*/
template<typename CharT, typename Traits>
friend std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const linear_congruential& lcr)
{ return os << lcr.m_x; }
template<typename _CharT, typename _Traits>
friend std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const linear_congruential& __lcr)
{ return __os << __lcr._M_x; }
/**
* Sets the state of the engine by reading its textual
* representation from @p is.
* 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.
* 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 os.
* @param __is The input stream.
* @param __lcr A linear_congruential random number generator.
* @returns __is.
*/
template<typename CharT, typename Traits>
friend std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is,
linear_congruential& lcr)
{ return is >> lcr.m_x; }
template<typename _CharT, typename _Traits>
friend std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<_CharT, _Traits>& __is,
linear_congruential& __lcr)
{ return __is >> __lcr._M_x; }
private:
template<class Gen>
template<class _Gen>
void
seed(Gen& g, true_type)
{ return seed(static_cast<unsigned long>(g)); }
seed(_Gen& __g, true_type)
{ return seed(static_cast<unsigned long>(__g)); }
template<class Gen>
template<class _Gen>
void
seed(Gen& g, false_type);
seed(_Gen& __g, false_type);
private:
UIntType m_x;
_UIntType _M_x;
};
/**
@ -456,52 +459,53 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* @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>
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)
__glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
public:
// types
typedef UIntType result_type ;
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;
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); }
mersenne_twister(unsigned long __value)
{ seed(__value); }
template<class Gen>
mersenne_twister(Gen& g)
{ seed(g); }
template<class _Gen>
mersenne_twister(_Gen& __g)
{ seed(__g); }
void
seed()
{ seed(5489UL); }
void
seed(unsigned long value);
seed(unsigned long __value);
template<class Gen>
template<class _Gen>
void
seed(Gen& g)
{ seed(g, typename is_fundamental<Gen>::type()); }
seed(_Gen& __g)
{ seed(__g, typename is_fundamental<_Gen>::type()); }
result_type
min() const
@ -514,18 +518,18 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator()();
private:
template<class Gen>
template<class _Gen>
void
seed(Gen& g, true_type)
{ return seed(static_cast<unsigned long>(g)); }
seed(_Gen& __g, true_type)
{ return seed(static_cast<unsigned long>(__g)); }
template<class Gen>
template<class _Gen>
void
seed(Gen& g, false_type);
seed(_Gen& __g, false_type);
private:
UIntType _M_x[state_size];
int _M_p;
_UIntType _M_x[state_size];
int _M_p;
};
/**
@ -565,7 +569,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* @var _M_p Current index of x(i - r).
* @endif
*/
template<typename _IntType, _IntType m, int s, int r>
template<typename _IntType, _IntType __m, int __s, int __r>
class subtract_with_carry
{
__glibcxx_class_requires(_IntType, _IntegerConcept)
@ -575,9 +579,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
typedef _IntType result_type;
// parameter values
static const _IntType modulus = m;
static const int long_lag = r;
static const int short_lag = s;
static const _IntType modulus = __m;
static const int long_lag = __r;
static const int short_lag = __s;
public:
/**
@ -592,16 +596,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* generator.
*/
explicit
subtract_with_carry(_IntType __value)
subtract_with_carry(unsigned long __value)
{ this->seed(__value); }
/**
* Constructs a % subtract_with_carry random number generator seeded from
* the PAD iterated by [__first, last).
*/
template<class Gen>
subtract_with_carry(Gen& g)
{ this->seed(g); }
template<class _Gen>
subtract_with_carry(_Gen& __g)
{ this->seed(__g); }
/**
* Seeds the initial state @f$ x_0 @f$ of the random number generator.
@ -619,16 +623,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* If @f$ x_{-1} = 0 @f$ set carry to 1, otherwise sets carry to 0.
*/
void
seed(_IntType __value = 19780503);
seed(unsigned long __value = 19780503);
/**
* Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry
* random number generator.
*/
template<class Gen>
template<class _Gen>
void
seed(Gen& g)
{ seed(g, typename is_fundamental<Gen>::type()); }
seed(_Gen& __g)
{ seed(__g, typename is_fundamental<_Gen>::type()); }
/**
* Gets the inclusive minimum value of the range of random integers
@ -667,7 +671,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
const subtract_with_carry& __rhs)
{
return ((__lhs._M_x[0] == __rhs._M_x[0])
&& (__lhs._M_x[r-1] == __rhs._M_x[r-1]));
&& (__lhs._M_x[__r - 1] == __rhs._M_x[__r - 1]));
}
/**
@ -687,7 +691,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a % subtract_with_carry random number
* genator engine @p x into the output stream @p os.
* genator engine @p x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A % subtract_with_carry random number generator engine.
@ -700,14 +704,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator<<(basic_ostream<_CharT, _Traits>& __os,
const subtract_with_carry& __x)
{
std::copy(__x._M_x, __x._M_x + r,
std::copy(__x._M_x, __x._M_x + __r,
std::ostream_iterator<_IntType>(__os, " "));
return __os << __x._M_carry;
}
/**
* Extracts the current state of a % subtract_with_carry random number
* gerator engine @p x from the input stream @p is.
* gerator engine @p x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A % subtract_with_carry random number generator engine.
@ -720,21 +724,21 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator>>(basic_istream<_CharT, _Traits>& __is,
subtract_with_carry& __x)
{
for (int __i = 0; __i < r; ++__i)
for (int __i = 0; __i < __r; ++__i)
__is >> __x._M_x[__i];
__is >> __x._M_carry;
return __is;
}
private:
template<class Gen>
template<class _Gen>
void
seed(Gen& g, true_type)
{ return seed(static_cast<unsigned long>(g)); }
seed(_Gen& __g, true_type)
{ return seed(static_cast<unsigned long>(__g)); }
template<class Gen>
template<class _Gen>
void
seed(Gen& g, false_type);
seed(_Gen& __g, false_type);
private:
int _M_p;
@ -747,9 +751,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* Produces random numbers from some base engine by discarding blocks of
* data.
*
* 0 <= @p r <= @p p
* 0 <= @p __r <= @p __p
*/
template<class UniformRandomNumberGenerator, int p, int r>
template<class _UniformRandomNumberGenerator, int __p, int __r>
class discard_block
{
// __glibcxx_class_requires(typename base_type::result_type,
@ -757,13 +761,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
public:
/** The type of the underlying generator engine. */
typedef UniformRandomNumberGenerator base_type;
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;
static const int block_size = __p;
static const int used_block = __r;
/**
* Constructs a default %discard_block engine.
@ -779,26 +783,26 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* Copies an existing base class random number geenerator.
* @param rng An existing (base class) engine object.
*/
explicit discard_block(const base_type& rng)
: _M_b(rng) , _M_n(0) { }
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.
* 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) { }
explicit discard_block(unsigned long __s)
: _M_b(__s), _M_n(0) { }
/**
* Generator constructs a %discard_block engine.
*
* @param g A seed generator function.
* @param __g A seed generator function.
*/
template<class Gen>
discard_block(Gen& g)
: _M_b(g), _M_n(0) { }
template<class _Gen>
discard_block(_Gen& __g)
: _M_b(__g), _M_n(0) { }
/**
* Reseeds the %discard_block object with the default seed for the
@ -813,12 +817,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Reseeds the %discard_block object with the given seed generator
* function.
* @param g A seed generator function.
* @param __g A seed generator function.
*/
template<class Gen>
void seed(Gen& g)
template<class _Gen>
void seed(_Gen& __g)
{
_M_b.seed(g);
_M_b.seed(__g);
_M_n = 0;
}
@ -882,7 +886,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a %discard_block random number
* genator engine @p x into the output stream @p os.
* genator engine @p x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %discard_block random number generator engine.
@ -898,7 +902,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts the current state of a % subtract_with_carry random number
* gerator engine @p x from the input stream @p is.
* gerator engine @p x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A %discard_block random number generator engine.
@ -941,43 +945,43 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* 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>
template<class _UniformRandomNumberGenerator1, int __s1,
class _UniformRandomNumberGenerator2, int __s2>
class xor_combine
{
// __glibcxx_class_requires(typename UniformRandomNumberGenerator1::
// __glibcxx_class_requires(typename _UniformRandomNumberGenerator1::
// result_type, ArithmeticTypeConcept);
// __glibcxx_class_requires(typename UniformRandomNumberGenerator2::
// __glibcxx_class_requires(typename _UniformRandomNumberGenerator2::
// result_type, ArithmeticTypeConcept);
public:
/** The type of the the first underlying generator engine. */
typedef UniformRandomNumberGenerator1 base1_type;
typedef _UniformRandomNumberGenerator1 base1_type;
/** The type of the the second underlying generator engine. */
typedef UniformRandomNumberGenerator2 base2_type;
typedef _UniformRandomNumberGenerator2 base2_type;
/** The type of the generated random value. */
typedef typename _Private::_Select<
(sizeof(base1_type) > sizeof(base2_type)),
base1_type,
base2_type
>::Type result_type;
>::_Type result_type;
// parameter values
static const int shift1 = s1;
static const int shift2 = s2;
static const int shift1 = __s1;
static const int shift2 = __s2;
// constructors and member function
xor_combine() { }
xor_combine(const base1_type& rng1, const base2_type& rng2)
: _M_b1(rng1), _M_b2(rng2) { }
xor_combine(const base1_type& __rng1, const base2_type& __rng2)
: _M_b1(__rng1), _M_b2(__rng2) { }
xor_combine(unsigned long s)
: _M_b1(s), _M_b2(s + 1) { }
xor_combine(unsigned long __s)
: _M_b1(__s), _M_b2(__s + 1) { }
template<class Gen>
xor_combine(Gen& g)
: _M_b1(g), _M_b2(g) { }
template<class _Gen>
xor_combine(_Gen& __g)
: _M_b1(__g), _M_b2(__g) { }
void
seed()
@ -986,12 +990,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
_M_b2.seed();
}
template<class Gen>
template<class _Gen>
void
seed(Gen& g)
seed(_Gen& __g)
{
_M_b1.seed(g);
_M_b2.seed(g);
_M_b1.seed(__g);
_M_b2.seed(__g);
}
const base1_type&
@ -1050,7 +1054,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a %xor_combine random number
* genator engine @p x into the output stream @p os.
* genator engine @p x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %xor_combine random number generator engine.
@ -1066,7 +1070,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts the current state of a %xor_combine random number
* gerator engine @p x from the input stream @p is.
* gerator engine @p x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A %xor_combine random number generator engine.
@ -1101,15 +1105,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
typedef unsigned int result_type;
// constructors, destructors and member functions
explicit random_device(const std::string& token = "unimplemented");
explicit random_device(const std::string& __token = "unimplemented");
result_type min() const;
result_type max() const;
double entropy() const;
result_type operator()();
private:
random_device(const random_device &);
void operator=(const random_device &);
random_device(const random_device&);
void operator=(const random_device&);
};
/* @} */ // group tr1_random_generators
@ -1212,7 +1216,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %unform_int random number distribution
* @p u from the input stream @p is.
* @p u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %uniform_int random number generator engine.
@ -1246,7 +1250,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Constructs a Bernoulli distribution with likelihood @p p.
*
* @param p [IN] The likelihood of a true result being returned. Must
* @param __p [IN] The likelihood of a true result being returned. Must
* be in the interval @f$ [0, 1] @f$.
*/
explicit
@ -1299,7 +1303,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %bernoulli_distribution random number distribution
* @p x into the output stream @p os.
* @p x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %bernoulli_distribution random number distribution.
@ -1315,7 +1319,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %bernoulli_distribution random number distribution
* @p u from the input stream @p is.
* @p u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %bernoulli_distribution random number generator engine.
@ -1358,7 +1362,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
}
/**
* Gets the distribution parameter @p.
* Gets the distribution parameter @p p.
*/
_RealType
p() const
@ -1389,7 +1393,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %geometric_distribution random number distribution
* @p x into the output stream @p os.
* @p x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %geometric_distribution random number distribution.
@ -1405,7 +1409,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %geometric_distribution random number distribution
* @p u from the input stream @p is.
* @p u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %geometric_distribution random number generator engine.
@ -1454,11 +1458,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Constructs a uniform_real object.
*
* @param min [IN] The lower bound of the distribution.
* @param max [IN] The upper bound of the distribution.
* @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));
uniform_real(_RealType __min = _RealType(0),
_RealType __max = _RealType(1));
result_type
min() const;
@ -1475,7 +1480,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %uniform_real random number distribution @p x into the
* output stream @p os.
* output stream @p __os.
*
* @param __os An output stream.
* @param __x A %uniform_real random number distribution.
@ -1491,7 +1496,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %unform_real random number distribution
* @p u from the input stream @p is.
* @p u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %uniform_real random number generator engine.
@ -1564,7 +1569,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %exponential_distribution random number distribution
* @p x into the output stream @p os.
* @p x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %exponential_distribution random number distribution.
@ -1580,7 +1585,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %exponential_distribution random number distribution
* @p u from the input stream @p is.
* @p u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %exponential_distribution random number generator engine.

View File

@ -46,93 +46,94 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
//
// Preconditions: a > 0, m > 0.
//
template<typename _Tp, _Tp a, _Tp c, _Tp m, bool _m_is_zero>
struct Mod
template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
struct _Mod
{
static _Tp
calc(_Tp x)
__calc(_Tp __x)
{
if (a == 1)
x %= m;
if (__a == 1)
__x %= __m;
else
{
static const _Tp q = m / a;
static const _Tp r = m % a;
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;
_Tp __t1 = __a * (__x % __q);
_Tp __t2 = __r * (__x / __q);
if (__t1 >= __t2)
__x = __t1 - __t2;
else
x = m - t2 + t1;
__x = __m - __t2 + __t1;
}
if (c != 0)
if (__c != 0)
{
const _Tp d = m - x;
if (d > c)
x += c;
const _Tp __d = __m - __x;
if (__d > __c)
__x += __c;
else
x = c - d;
__x = __c - __d;
}
return x;
return __x;
}
};
// Special case for m==0 -- use unsigned integer overflow as modulo
// 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>
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; }
__calc(_Tp __x)
{ return __a * __x + __c; }
};
// 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>
template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
inline _Tp
mod(_Tp x)
{ return Mod<_Tp, a, c, m, m == 0>::calc(x); }
__mod(_Tp __x)
{ return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); }
// Like the above, for a==1, c==0, in terms of w.
template<typename _Tp, _Tp w, bool>
struct Mod_w
// Like the above, for a == 1, c == 0, in terms of w.
template<typename _Tp, _Tp __w, bool>
struct _Mod_w
{
static _Tp
calc(_Tp x)
{ return x % (_Tp(1) << w); }
__calc(_Tp __x)
{ return __x % (_Tp(1) << __w); }
};
template<typename _Tp, _Tp w>
struct Mod_w<_Tp, w, true>
template<typename _Tp, _Tp __w>
struct _Mod_w<_Tp, __w, true>
{
static _Tp
calc(_Tp x)
{ return x; }
__calc(_Tp __x)
{ return __x; }
};
template<typename _Tp, _Tp w>
template<typename _Tp, _Tp __w>
inline _Tp
mod_w(_Tp x)
{ return Mod_w<_Tp, w, w == std::numeric_limits<_Tp>::digits>::calc(x); }
__mod_w(_Tp __x)
{ return _Mod_w<_Tp, __w,
__w == std::numeric_limits<_Tp>::digits>::__calc(__x); }
// Selector to return the maximum value possible that will fit in
// @p w bits of @p _Tp.
template<typename _Tp, _Tp w, bool>
struct Max_w
// @p __w bits of @p _Tp.
template<typename _Tp, _Tp __w, bool>
struct _Max_w
{
static _Tp
value()
{ return (_Tp(1) << w) - 1; }
__value()
{ return (_Tp(1) << __w) - 1; }
};
template<typename _Tp, _Tp w>
struct Max_w<_Tp, w, true>
template<typename _Tp, _Tp __w>
struct _Max_w<_Tp, __w, true>
{
static _Tp
value()
__value()
{ return std::numeric_limits<_Tp>::max(); }
};
@ -140,53 +141,53 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Constructs the LCR engine with integral seed @p x0.
* Constructs the LCR engine with integral seed @p __x0.
*/
template<class UIntType, UIntType a, UIntType c, UIntType m>
linear_congruential<UIntType, a, c, m>::
linear_congruential(unsigned long x0)
{ this->seed(x0); }
template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
linear_congruential<_UIntType, __a, __c, __m>::
linear_congruential(unsigned long __x0)
{ this->seed(__x0); }
/**
* Constructs the LCR engine with seed generated from @p g.
* Constructs the LCR engine with seed generated from @p __g.
*/
template<class UIntType, UIntType a, UIntType c, UIntType m>
template<class Gen>
linear_congruential<UIntType, a, c, m>::
linear_congruential(Gen& g)
{ this->seed(g); }
template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<class _Gen>
linear_congruential<_UIntType, __a, __c, __m>::
linear_congruential(_Gen& __g)
{ this->seed(__g); }
/**
* Seeds the LCR with integral value @p x0, adjusted so that the
* 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>
template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
void
linear_congruential<UIntType, a, c, m>::
seed(unsigned long x0)
linear_congruential<_UIntType, __a, __c, __m>::
seed(unsigned long __x0)
{
if ((_Private::mod<UIntType, 1, 0, m>(c) == 0)
&& (_Private::mod<UIntType, 1, 0, m>(x0) == 0))
m_x = _Private::mod<UIntType, 1, 0, m>(1);
if ((_Private::__mod<_UIntType, 1, 0, __m>(__c) == 0)
&& (_Private::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
_M_x = _Private::__mod<_UIntType, 1, 0, __m>(1);
else
m_x = _Private::mod<UIntType, 1, 0, m>(x0);
_M_x = _Private::__mod<_UIntType, 1, 0, __m>(__x0);
}
/**
* Seeds the LCR engine with a value generated by @p g.
* Seeds the LCR engine with a value generated by @p __g.
*/
template<class UIntType, UIntType a, UIntType c, UIntType m>
template<class Gen>
template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<class _Gen>
void
linear_congruential<UIntType, a, c, m>::
seed(Gen& g, false_type)
linear_congruential<_UIntType, __a, __c, __m>::
seed(_Gen& __g, false_type)
{
UIntType x0 = g();
if ((_Private::mod<UIntType, 1, 0, m>(c) == 0)
&& (_Private::mod<UIntType, 1, 0, m>(x0) == 0))
m_x = _Private::mod<UIntType, 1, 0, m>(1);
_UIntType __x0 = __g();
if ((_Private::__mod<_UIntType, 1, 0, __m>(__c) == 0)
&& (_Private::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
_M_x = _Private::__mod<_UIntType, 1, 0, __m>(1);
else
m_x = _Private::mod<UIntType, 1, 0, m>(x0);
_M_x = _Private::__mod<_UIntType, 1, 0, __m>(__x0);
}
/**
@ -194,135 +195,146 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* returned by operator(). The return value of this function does not
* change during the lifetime of the object..
*
* The minumum depends on the @p c parameter: if it is zero, the
* The minumum depends on the @p __c parameter: if it is zero, the
* minimum generated must be > 0, otherwise 0 is allowed.
*/
template<class UIntType, UIntType a, UIntType c, UIntType m>
typename linear_congruential<UIntType, a, c, m>::result_type
linear_congruential<UIntType, a, c, m>::
template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
typename linear_congruential<_UIntType, __a, __c, __m>::result_type
linear_congruential<_UIntType, __a, __c, __m>::
min() const
{ return (_Private::mod<UIntType, 1, 0, m>(c) == 0) ? 1 : 0; }
{ return (_Private::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; }
/**
* Gets the maximum possible value of the generated range.
*
* For a linear congruential generator, the maximum is always @p m - 1.
* For a linear congruential generator, the maximum is always @p __m - 1.
*/
template<class UIntType, UIntType a, UIntType c, UIntType m>
typename linear_congruential<UIntType, a, c, m>::result_type
linear_congruential<UIntType, a, c, m>::
template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
typename linear_congruential<_UIntType, __a, __c, __m>::result_type
linear_congruential<_UIntType, __a, __c, __m>::
max() const
{ return (m == 0) ? std::numeric_limits<UIntType>::max() : (m - 1); }
{ return (__m == 0) ? std::numeric_limits<_UIntType>::max() : (__m - 1); }
/**
* 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>::
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 = _Private::mod<UIntType, a, c, m>(m_x);
return m_x;
_M_x = _Private::__mod<_UIntType, __a, __c, __m>(_M_x);
return _M_x;
}
template<class _UInt, int w, int n, int m, int r,
_UInt a, int u, int s,
_UInt b, int t, _UInt c, int l>
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<_UInt, w, n, m, r, a, u, s, b, t, c, l>::
seed(unsigned long value)
mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
__b, __t, __c, __l>::
seed(unsigned long __value)
{
_M_x[0] = _Private::mod_w<_UInt, w>(value);
_M_x[0] = _Private::__mod_w<_UIntType, __w>(__value);
for (int i = 1; i < n; ++i)
for (int __i = 1; __i < state_size; ++__i)
{
_UInt x = _M_x[i - 1];
x ^= x >> (w - 2);
x *= 1812433253ul;
x += i;
_M_x[i] = _Private::mod_w<_UInt, w>(x);
_UIntType __x = _M_x[__i - 1];
__x ^= __x >> (__w - 2);
__x *= 1812433253ul;
__x += __i;
_M_x[__i] = _Private::__mod_w<_UIntType, __w>(__x);
}
_M_p = n;
_M_p = state_size;
}
template<class _UInt, int w, int n, int m, int r,
_UInt a, int u, int s,
_UInt b, int t, _UInt c, int l>
template<class Gen>
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<_UInt, w, n, m, r, a, u, s, b, t, c, l>::
seed(Gen& gen, false_type)
mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
__b, __t, __c, __l>::
seed(_Gen& __gen, false_type)
{
for (int i = 0; i < n; ++i)
_M_x[i] = _Private::mod_w<_UInt, w>(gen());
_M_p = n;
for (int __i = 0; __i < state_size; ++__i)
_M_x[__i] = _Private::__mod_w<_UIntType, __w>(__gen());
_M_p = state_size;
}
template<class _UInt, int w, int n, int m, int r,
_UInt a, int u, int s,
_UInt b, int t, _UInt c, int l>
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<_UInt, w, n, m, r, a, u, s, b, t, c, l>::result_type
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>::
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>::
max() const
{
using _Private::Max_w;
using _Private::_Max_w;
using std::numeric_limits;
return Max_w<_UInt, w, w == numeric_limits<_UInt>::digits>::value();
return _Max_w<_UIntType, __w,
__w == numeric_limits<_UIntType>::digits>::__value();
}
template<class _UInt, int w, int n, int m, int r,
_UInt a, int u, int s,
_UInt b, int t, _UInt c, int l>
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<_UInt, w, n, m, r, a, u, s, b, t, c, l>::result_type
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>::
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 >= n)
if (_M_p >= state_size)
{
const _UInt upper_mask = (~_UInt()) << r;
const _UInt lower_mask = ~upper_mask;
const _UIntType __upper_mask = (~_UIntType()) << __r;
const _UIntType __lower_mask = ~__upper_mask;
for (int k = 0; k < (n - m); ++k)
for (int __k = 0; __k < (__n - __m); ++__k)
{
_UInt 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);
_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)
for (int __k = (__n - __m); __k < (__n - 1); ++__k)
{
_UInt 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[__k] & __upper_mask)
| (_M_x[__k + 1] & __lower_mask));
_M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__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);
result_type __z = _M_x[_M_p++];
__z ^= (__z >> __u);
__z ^= (__z << __s) & __b;
__z ^= (__z << __t) & __c;
__z ^= (__z >> __l);
return z;
return __z;
}
template<typename _IntType, _IntType m, int s, int r>
template<typename _IntType, _IntType __m, int __s, int __r>
void
subtract_with_carry<_IntType, m, s, r>::
seed(_IntType __value)
subtract_with_carry<_IntType, __m, __s, __r>::
seed(unsigned long __value)
{
std::tr1::linear_congruential<unsigned long, 40014, 0, 2147483563>
lcg(__value);
__lcg(__value);
for (int i = 0; i < long_lag; ++i)
_M_x[i] = _Private::mod<_IntType, 1, 0, modulus>(lcg());
for (int __i = 0; __i < long_lag; ++__i)
_M_x[__i] = _Private::__mod<_IntType, 1, 0, modulus>(__lcg());
_M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
_M_p = 0;
@ -337,22 +349,22 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// center.
//
template<typename _IntType, _IntType __m, int __s, int __r>
template<class Gen>
template<class _Gen>
void
subtract_with_carry<_IntType, __m, __s, __r>::
seed(Gen& gen, false_type)
seed(_Gen& __gen, false_type)
{
const int n = (std::numeric_limits<_IntType>::digits + 31) / 32;
for (int i = 0; i < long_lag; ++i)
const int __n = (std::numeric_limits<_IntType>::digits + 31) / 32;
for (int __i = 0; __i < long_lag; ++__i)
{
_M_x[i] = 0;
unsigned long factor = 1;
for (int j = 0; j < n; ++j)
_M_x[__i] = 0;
unsigned long __factor = 1;
for (int __j = 0; __j < __n; ++__j)
{
_M_x[i] += gen() * factor;
factor *= 0x80000000;
_M_x[__i] += __gen() * __factor;
__factor *= 0x80000000;
}
_M_x[i] = _Private::mod<_IntType, 1, 0, modulus>(_M_x[i]);
_M_x[__i] = _Private::__mod<_IntType, 1, 0, modulus>(_M_x[__i]);
}
_M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
_M_p = 0;
@ -364,35 +376,36 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator()()
{
// Derive short lag index from current index.
int ps = _M_p - short_lag;
if (ps < 0)
ps += long_lag;
int __ps = _M_p - short_lag;
if (__ps < 0)
__ps += long_lag;
// Calculate new x(i) without overflow or division.
_IntType xi;
if (_M_x[ps] >= _M_x[_M_p] + _M_carry)
_IntType __xi;
if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
{
xi = _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];
__xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps];
_M_carry = 1;
}
_M_x[_M_p++] = xi;
_M_x[_M_p++] = __xi;
// Adjust current index to loop around in ring buffer.
if (_M_p >= long_lag)
_M_p = 0;
return xi;
return __xi;
}
template<class _E, int __p, int __r>
typename discard_block<_E, __p, __r>::result_type
discard_block<_E, __p, __r>::
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)