[multiple changes]

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

	* include/tr1/random.tcc (Max::value()): Cast 1 to Tp(1) and
	adjust shift count to w; rename as Max_w.
	(struct Mod_w): New.
	(mersenne_twister<>::seed(Gen&, false_type): Use the latter.
	(mersenne_twister<>::operator()()): Fix ~0ul to ~_UInt().
	* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
	cons/default.cc: Fix ~0ul to 2^32-1.
	* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
	cons/gen1.cc: Likewise.

2006-06-05  Stephen M. Webb  <stephen.webb@bregmasoft.com>

	* include/tr1/random: New.
	* include/tr1/random.tcc: Likewise.
	* include/Makefile.am: Add.
	* testsuite/tr1/5_numerical_facilies/random/ranlux3.cc: New.
	* testsuite/tr1/5_numerical_facilies/random/ranlux4.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/mt19937.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/variate_generator/
	requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	cons/seed1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	cons/seed2.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	cons/default.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	cons/gen1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	operators/equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	operators/not_equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
	operators/serialize.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/uniform_real/
	requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/discard_block/
	requirements/requirements.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	cons/seed1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	cons/seed2.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	cons/default.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	cons/gen1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	requirements/non_uint_neg.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	operators/equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	operators/not_equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
	operators/serialize.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/xor_combine/
	requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/minstd_rand.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/minstd_rand0.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/uniform_int/
	cons/range.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/uniform_int/
	cons/default.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/uniform_int/
	cons/range_neg.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/uniform_int/
	requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
	cons/seed1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
	cons/seed2.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
	cons/default.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
	cons/gen1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
	requirements/typedefs.cc: Likewise.
	* include/Makefile.in: Regenerate.
	* testsuite/tr1/headers.cc: Update.

From-SVN: r114384
This commit is contained in:
Paolo Carlini 2006-06-05 07:33:18 +00:00
parent 2b643edaf8
commit 86ad0dd600
41 changed files with 3629 additions and 0 deletions

View File

@ -1,3 +1,88 @@
2006-06-05 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random.tcc (Max::value()): Cast 1 to Tp(1) and
adjust shift count to w; rename as Max_w.
(struct Mod_w): New.
(mersenne_twister<>::seed(Gen&, false_type): Use the latter.
(mersenne_twister<>::operator()()): Fix ~0ul to ~_UInt().
* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
cons/default.cc: Fix ~0ul to 2^32-1.
* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
cons/gen1.cc: Likewise.
2006-06-05 Stephen M. Webb <stephen.webb@bregmasoft.com>
* include/tr1/random: New.
* include/tr1/random.tcc: Likewise.
* include/Makefile.am: Add.
* testsuite/tr1/5_numerical_facilies/random/ranlux3.cc: New.
* testsuite/tr1/5_numerical_facilies/random/ranlux4.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/mt19937.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/variate_generator/
requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
cons/seed1.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
cons/seed2.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
cons/default.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
cons/gen1.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
operators/equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
operators/not_equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/subtract_with_carry/
operators/serialize.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/uniform_real/
requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/discard_block/
requirements/requirements.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
cons/seed1.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
cons/seed2.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
cons/default.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
cons/gen1.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
requirements/non_uint_neg.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
operators/equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
operators/not_equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/linear_congruential/
operators/serialize.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/xor_combine/
requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/minstd_rand.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/minstd_rand0.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/uniform_int/
cons/range.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/uniform_int/
cons/default.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/uniform_int/
cons/range_neg.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/uniform_int/
requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
cons/seed1.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
cons/seed2.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
cons/default.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
cons/gen1.cc: Likewise.
* testsuite/tr1/5_numerical_facilies/random/mersenne_twister/
requirements/typedefs.cc: Likewise.
* include/Makefile.in: Regenerate.
* testsuite/tr1/headers.cc: Update.
2006-06-04 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/27867

View File

@ -512,6 +512,8 @@ tr1_headers = \
${tr1_srcdir}/math.h \
${tr1_srcdir}/memory \
${tr1_srcdir}/mu_iterate.h \
${tr1_srcdir}/random \
${tr1_srcdir}/random.tcc \
${tr1_srcdir}/ref_fwd.h \
${tr1_srcdir}/ref_wrap_iterate.h \
${tr1_srcdir}/repeat.h \

View File

@ -731,6 +731,8 @@ tr1_headers = \
${tr1_srcdir}/math.h \
${tr1_srcdir}/memory \
${tr1_srcdir}/mu_iterate.h \
${tr1_srcdir}/random \
${tr1_srcdir}/random.tcc \
${tr1_srcdir}/ref_fwd.h \
${tr1_srcdir}/ref_wrap_iterate.h \
${tr1_srcdir}/repeat.h \

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,422 @@
// random number generation (out of line) -*- C++ -*-
// Copyright (C) 2006 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.
#include <limits>
namespace std
{
_GLIBCXX_BEGIN_NAMESPACE(tr1)
/*
* Implementation-space details.
*/
namespace _Private
{
// 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 _m_is_zero>
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; }
};
// 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); }
// 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); }
};
template<typename _Tp, _Tp w>
struct Mod_w<_Tp, w, true>
{
static _Tp
calc(_Tp x)
{ return 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
{
static _Tp
value()
{ return (_Tp(1) << w) - 1; }
};
template<typename _Tp, _Tp w>
struct Max_w<_Tp, w, true>
{
static _Tp
value()
{ return std::numeric_limits<_Tp>::max(); }
};
} // namespace _Private
/**
* 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); }
/**
* 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); }
/**
* 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 ((_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);
}
/**
* 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 ((_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);
}
/**
* Returns a value that is less than or equal to all values potentially
* 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
* 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>::
min() const
{ 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.
*/
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); }
/**
* 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 = _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>
void
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>::
seed(unsigned long value)
{
if (value == 0)
value = 4357;
#if 0
// @todo handle case numeric_limits<_UInt>::digits > 32
if (std::numeric_limits<_UInt>::digits > 32)
{
std::tr1::linear_congruential<unsigned long, 69069, 0, 2**32> lcg(value);
seed(lcg);
}
else
{
std::tr1::linear_congruential<unsigned long, 69069, 0, 0> lcg(value);
seed(lcg);
}
#else
std::tr1::linear_congruential<unsigned long, 69069, 0, 0> lcg(value);
seed(lcg);
#endif
}
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>
void
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>::
seed(Gen& gen, false_type)
{
using _Private::Mod_w;
using std::numeric_limits;
for (int i = 0; i < state_size; ++i)
_M_x[i] = Mod_w<_UInt, w,
w == numeric_limits<_UInt>::digits>::calc(gen());
_M_p = state_size + 1;
}
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>
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>::
max() const
{
using _Private::Max_w;
using std::numeric_limits;
return Max_w<_UInt, w, w == numeric_limits<_UInt>::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>
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>::
operator()()
{
// reload the vector - cost is O(n) amortized over n calls.
if (_M_p >= state_size)
{
const _UInt upper_mask = (~_UInt()) << r;
const _UInt lower_mask = ~upper_mask;
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);
}
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);
}
_M_p = 0;
}
// Calculate x(i)
result_type y = _M_x[_M_p++];
y ^= (y >> u);
y ^= (y << s) & b;
y ^= (y << t) & c;
y ^= (y >> l);
return y;
}
template<typename _IntType, _IntType m, int s, int r>
void
subtract_with_carry<_IntType, m, s, r>::
seed(_IntType __value)
{
std::tr1::linear_congruential<unsigned long, 40014, 0, 2147483563>
lcg(__value);
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;
}
//
// This implementation differs from the tr1 spec because the tr1 spec refused
// to make any sense to me: the exponent of the factor in the spec goes from
// 1 to (n-1), but it would only make sense to me if it went from 0 to (n-1).
//
// This algorithm is still problematic because it can overflow left right and
// center.
//
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<_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] += gen() * factor;
factor *= 0x80000000;
}
_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;
}
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
_IntType 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<class _E, int __p, int __r>
typename discard_block<_E, __p, __r>::result_type
discard_block<_E, __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();
}
_GLIBCXX_END_NAMESPACE
}

View File

@ -0,0 +1,40 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.5 Class template linear_congruential
// 5.1.1 [1] Table 15
#include <tr1/random>
void
test01()
{
using namespace std::tr1;
typedef discard_block
<
subtract_with_carry<long, (1 << 24), 10, 24>,
389, 24
> test_type;
typedef test_type::result_type result_type;
}

View File

@ -0,0 +1,43 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 class template linear_congruential [tr.rand.eng.lcong]
// 5.1.4.1 [4]
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
linear_congruential<unsigned long, 48271, 0, 2147483647> x;
VERIFY( x.min() == 1 );
VERIFY( x.max() == 2147483647-1 );
VERIFY( x() == 48271 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,50 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 class template linear_congruential [tr.rand.eng.lcong]
// 5.1.1 Table 16 line 3 template ctor(gen)
#include <ctime>
#include <tr1/random>
#include <testsuite_hooks.h>
// a not untypical initialization function
unsigned long
gen()
{
return std::time(0);
}
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
linear_congruential<unsigned long, 48271, 0, 2147483647> x(gen);
VERIFY( x.min() == 1 );
VERIFY( x.max() == 2147483647-1 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,40 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 class template linear_congruential [tr.rand.eng.lcong]
// 5.1.1 [4] para 2
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
unsigned long seed = 2;
linear_congruential<unsigned long, 48271, 0, 2147483647> x(seed);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,40 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 class template linear_congruential [tr.rand.eng.lcong]
// 5.1.1 [4] para 2
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
double seed = 2.0;
linear_congruential<unsigned long, 48271, 0, 2147483647> x(seed);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 Class template linear_congruential
// 5.1 [3] Table 16
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::minstd_rand0 a;
std::tr1::minstd_rand0 b;
std::tr1::minstd_rand0 c(120);
VERIFY( a == b );
VERIFY( !(a == c) );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 Class template linear_congruential
// 5.1 [3] Table 16
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::minstd_rand0 a;
std::tr1::minstd_rand0 b;
std::tr1::minstd_rand0 c(120);
VERIFY( !(a != b) );
VERIFY( a != c );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,50 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 Class template linear_congruential
// 5.1 [3] Table 16
#include <sstream>
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::stringstream str;
std::tr1::minstd_rand0 a;
std::tr1::minstd_rand0 b;
a(); // advance
str << a;
VERIFY( a != b );
str >> b;
VERIFY( a == b );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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 "-D_GLIBCXX_CONCEPT_CHECKS" }
// { dg-error "not a valid type" "" { target *-*-* } 37 }
// { dg-error "invalid type" "" { target *-*-* } 37 }
// 5.1.4.1 class template linear_congruential [tr.rand.eng.lcong]
// 5.1.4.1 [4]
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
linear_congruential<double, 48271, 0, 2147483647> x;
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,34 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.1 Class template linear_congruential
// 5.1.1 [1] Table 15
#include <tr1/random>
void
test01()
{
typedef std::tr1::linear_congruential<unsigned long, 2, 0, 4> test_type;
typedef test_type::result_type result_type;
}

View File

@ -0,0 +1,48 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.2 class template mersenne_twister [tr.rand.eng.mers]
// 5.1.1 Table 16 line 1 default ctor
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
mersenne_twister<
unsigned long, 32, 624, 397, 31,
0x9908b0dful, 11, 7,
0x9d2c5680ul, 15,
0xefc60000ul, 18> x;
VERIFY( x.min() == 0 );
VERIFY( x.max() == 4294967295ul );
VERIFY( x() == 4290933890ul );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,54 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.2 class template mersenne_twister [tr.rand.eng.mers]
// 5.1.1 Table 16 line 3 Gen ctor
#include <ctime>
#include <tr1/random>
#include <testsuite_hooks.h>
// a not untypical initialization function
unsigned long
gen()
{
return std::time(0);
}
void
test01()
{
using namespace std::tr1;
mersenne_twister<
unsigned long, 32, 624, 397, 31,
0x9908b0dful, 11, 7,
0x9d2c5680ul, 15,
0xefc60000ul, 18> x(gen);
VERIFY( x.min() == 0 );
VERIFY( x.max() == 4294967295ul );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.2 class template mersenne_twister [tr.rand.eng.mers]
// 5.1.1 Table 16 line 2 seed ctor
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
unsigned long seed = 2;
mersenne_twister<
unsigned long, 32, 624, 397, 31,
0x9908b0dful, 11, 7,
0x9d2c5680ul, 15,
0xefc60000ul, 18> x(seed);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,45 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.2 class template mersenne_twister [tr.rand.eng.mers]
// 5.1.1 Table 16 line 2 seed ctor
// 5.1.1 (4) point 2: Gen is a fundamental type.
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
double seed = 2.0;
mersenne_twister<
unsigned long, 32, 624, 397, 31,
0x9908b0dful, 11, 7,
0x9d2c5680ul, 15,
0xefc60000ul, 18> x(seed);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,38 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.2 Class template mersenne_twister
// 5.1.1 [1] Table 15
#include <tr1/random>
void
test01()
{
typedef std::tr1::mersenne_twister<unsigned long,
32, 624, 397, 31,
0x9908b0df, 11, 7,
0x9d2c5680, 15,
0xefc60000, 18> test_type;
typedef test_type::result_type result_type;
}

View File

@ -0,0 +1,43 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.5 Engines with predefined parameters
// 5.1.5 [1]
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::minstd_rand a;
for (int i = 0; i < 9999; ++i)
a();
VERIFY( a() == 399268537 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,43 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.5 Engines with predefined parameters
// 5.1.5 [1]
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::minstd_rand0 a;
for (int i = 0; i < 9999; ++i)
a();
VERIFY( a() == 1043618065 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,43 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.5 Engines with predefined parameters
// 5.1.5 [2]
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::mt19937 a;
for (int i = 0; i < 9999; ++i)
a();
VERIFY( a() == 3346425566ul );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,44 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.5 Engines with predefined parameters
// 5.1.5 [3]
#include <iostream>
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::ranlux3 a;
for (int i = 0; i < 9999; ++i)
a();
VERIFY( a() == 5957620 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,43 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.5 Engines with predefined parameters
// 5.1.5 [3]
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::tr1::ranlux4 a;
for (int i = 0; i < 9999; ++i)
a();
VERIFY( a() == 8587295 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,43 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 class template subtract_with_carry [tr.rand.eng.sub]
// 5.1.1 Table 16 line 1 default ctor
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x;
VERIFY( x.min() == 0 );
VERIFY( x.max() == ((1<<24)-1) );
VERIFY( x() == 15039276 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,50 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 class template subtract_with_carry [tr.rand.eng.sub]
// 5.1.1 Table 16 line 3 Gen ctor
#include <ctime>
#include <tr1/random>
#include <testsuite_hooks.h>
// a not untypical initialization function
unsigned long
gen()
{
return std::time(0);
}
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x(gen);
VERIFY( x.min() == 0 );
VERIFY( x.max() == ((1 << 24) - 1) );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,40 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 class template subtract_with_carry [tr.rand.eng.sub]
// 5.1.1 Table 16 line 2 seed ctor
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
unsigned long seed = 2;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x(seed);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,41 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 class template subtract_with_carry [tr.rand.eng.sub]
// 5.1.1 Table 16 line 2 seed ctor
// 5.1.1 (4) point 2: Gen is a fundamental type.
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
double seed = 2.0;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x(seed);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,50 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 class template subtract_with_carry [tr.rand.eng.sub]
// 5.1.1 Table 16
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> u;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> v;
VERIFY( u == v );
for (int i = 0; i < 100; ++i)
{
u();
v();
}
VERIFY( u == v );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,43 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 class template subtract_with_carry [tr.rand.eng.sub]
// 5.1.1 Table 16
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> u(1);
subtract_with_carry<unsigned long, (1 << 24), 10, 24> v(2);
VERIFY( u != v );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,51 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 class template subtract_with_carry [tr.rand.eng.sub]
// 5.1.1 Table 16
#include <sstream>
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using std::tr1::subtract_with_carry;
std::stringstream str;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> u;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> v;
u(); // advance
str << u;
VERIFY( u != v );
str >> v;
VERIFY( u == v );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,34 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.3 Class template subtract_with_carry
// 5.1.1 [1] Table 15
#include <tr1/random>
void
test01()
{
typedef std::tr1::subtract_with_carry<long, 8, 2, 4> test_type;
typedef test_type::result_type result_type;
}

View File

@ -0,0 +1,42 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.7.1 class template uniform_int
// 5.1.7.1 [2] constructors and member functions
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
uniform_int<int> u;
VERIFY( u.min() == 0 );
VERIFY( u.max() == 9 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,42 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.7.1 class template uniform_int
// 5.1.7.1 [2] constructors and member functions
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std::tr1;
uniform_int<int> u(1, 20);
VERIFY( u.min() == 1 );
VERIFY( u.max() == 20 );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,42 @@
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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 "-D_GLIBCXX_DEBUG" }
// 5.1.7.1 class template uniform_int
// 5.1.7.1 [2] constructors and member functions
#include <tr1/random>
#include <testsuite_hooks.h>
void
test01()
{
using namespace std::tr1;
uniform_int<int> u(20, 1);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,37 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.7.1 Class template uniform_int
// 5.1.1 [7] Table 17
#include <tr1/random>
void
test01()
{
using namespace std::tr1;
typedef uniform_int<int> test_type;
typedef test_type::input_type input_type;
typedef test_type::result_type result_type;
}

View File

@ -0,0 +1,37 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.7.6 Class template uniform_int [tr.rand.dist.runif]
// 5.1.1 [7] Table 17
#include <tr1/random>
void
test01()
{
using namespace std::tr1;
typedef uniform_real<double> test_type;
typedef test_type::input_type input_type;
typedef test_type::result_type result_type;
}

View File

@ -0,0 +1,42 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.3 class template variate_generator
#include <tr1/random>
void
test01()
{
using namespace std::tr1;
typedef variate_generator
<
linear_congruential<unsigned long, 16807 , 0 , 2147483647>,
uniform_int<int>
> test_type;
typedef test_type::engine_type engine_type;
typedef test_type::engine_value_type engine_value_type;
typedef test_type::distribution_type distribution_type;
typedef test_type::result_type result_type;
}

View File

@ -0,0 +1,40 @@
// { dg-do compile }
//
// 2006-06-04 Stephen M. Webb <stephen.webb@bregmasoft.com>
//
// Copyright (C) 2006 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.
// 5.1.4.6 Class template xor_combine
// 5.1.1 [1] Table 15
#include <tr1/random>
void
test01()
{
using namespace std::tr1;
typedef xor_combine
<
subtract_with_carry<long, (1 << 24), 10, 24>, 1,
linear_congruential<unsigned long, 16807, 0, 2147483647>, 2
> test_type;
typedef test_type::result_type result_type;
}

View File

@ -45,6 +45,7 @@
#include <tr1/limits.h>
#include <tr1/math.h>
#include <tr1/memory>
#include <tr1/random>
#include <tr1/stdarg.h>
#include <tr1/stdbool.h>
#include <tr1/stdint.h>