Commit 9aa53350 by Paolo Carlini Committed by Paolo Carlini

random (class subtract_with_carry_01): Add.

2006-08-22  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/random (class subtract_with_carry_01): Add.
	* include/tr1/random.tcc (subtract_with_carry_01<>::
	seed(unsigned long), subtract_with_carry_01<>::
	seed(_Gen&, false_type), subtract_with_carry_01<>::
	operator(), operator<<(std::basic_ostream<>&, const
	subtract_with_carry_01<>&), operator>>(std::basic_istream<>&,
	subtract_with_carry_01<>&)): Define.
	* testsuite/tr1/5_numerical_facilities/random/ranlux3_01.cc:
	New.
	* testsuite/tr1/5_numerical_facilities/random/ranlux4_01.cc:
	Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/cons/seed1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/cons/seed2.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/cons/default.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/cons/gen1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/operators/equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/operators/not_equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry_01/operators/serialize.cc: Likewise.

	* docs/html/ext/howto.html: Add two implemented TR1 issues.

	* include/tr1/random.tcc (struct _To_Unsigned_Type): Move...
	* include/tr1/random: ... here.
	(class subtract_with_carry): Use it everywhere.

	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/cons/seed1.cc: Qualify 1 as 1UL.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/cons/seed2.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/cons/default.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/cons/gen1.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/requirements/typedefs.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/operators/equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/operators/not_equal.cc: Likewise.
	* testsuite/tr1/5_numerical_facilities/random/
	subtract_with_carry/operators/serialize.cc: Likewise.

From-SVN: r116327
parent 8a613cae
2006-08-22 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (class subtract_with_carry_01): Add.
* include/tr1/random.tcc (subtract_with_carry_01<>::
seed(unsigned long), subtract_with_carry_01<>::
seed(_Gen&, false_type), subtract_with_carry_01<>::
operator(), operator<<(std::basic_ostream<>&, const
subtract_with_carry_01<>&), operator>>(std::basic_istream<>&,
subtract_with_carry_01<>&)): Define.
* testsuite/tr1/5_numerical_facilities/random/ranlux3_01.cc:
New.
* testsuite/tr1/5_numerical_facilities/random/ranlux4_01.cc:
Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/cons/seed1.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/cons/seed2.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/cons/default.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/cons/gen1.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/operators/equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/operators/not_equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry_01/operators/serialize.cc: Likewise.
* docs/html/ext/howto.html: Add two implemented TR1 issues.
* include/tr1/random.tcc (struct _To_Unsigned_Type): Move...
* include/tr1/random: ... here.
(class subtract_with_carry): Use it everywhere.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/cons/seed1.cc: Qualify 1 as 1UL.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/cons/seed2.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/cons/default.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/cons/gen1.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/requirements/typedefs.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/operators/equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/operators/not_equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/
subtract_with_carry/operators/serialize.cc: Likewise.
2006-08-20 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (gamma_distribution<>::_M_initialize,
......
......@@ -574,6 +574,18 @@
<code>at(const key_type&amp;)</code> to <code>std::map</code>.
</dd>
<dt><a href="lwg-defects.html#508">508</a>:
<em>Bad parameters for ranlux64_base_01</em>
</dt>
<dd>Fix the parameters.
</dd>
<dt><a href="lwg-active.html#512">512</a>:
<em>Seeding subtract_with_carry_01 from a single unsigned long</em>
</dt>
<dd>Construct a <code>linear_congruential</code> engine and seed with it.
</dd>
<dt><a href="lwg-active.html#538">538</a>:
<em>DR 538. 241 again: Does unique_copy() require CopyConstructible
and Assignable?</em>
......
......@@ -32,7 +32,7 @@ namespace std
_GLIBCXX_BEGIN_NAMESPACE(tr1)
/*
* Implementation-space details.
* (Further) implementation-space details.
*/
namespace
{
......@@ -101,29 +101,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
static const std::streamsize __value =
2 + std::numeric_limits<_RealType>::digits * 3010/10000;
};
template<typename _ValueT>
struct _To_Unsigned_Type
{ typedef _ValueT _Type; };
template<>
struct _To_Unsigned_Type<short>
{ typedef unsigned short _Type; };
template<>
struct _To_Unsigned_Type<int>
{ typedef unsigned int _Type; };
template<>
struct _To_Unsigned_Type<long>
{ typedef unsigned long _Type; };
#ifdef _GLIBCXX_USE_LONG_LONG
template<>
struct _To_Unsigned_Type<long long>
{ typedef unsigned long long _Type; };
#endif
} // anonymous namespace
......@@ -376,7 +353,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
__lcg(__value);
for (int __i = 0; __i < long_lag; ++__i)
_M_x[__i] = __mod<_IntType, 1, 0, modulus>(__lcg());
_M_x[__i] = __mod<_UIntType, 1, 0, modulus>(__lcg());
_M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
_M_p = 0;
......@@ -388,13 +365,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
subtract_with_carry<_IntType, __m, __s, __r>::
seed(_Gen& __gen, false_type)
{
const int __n = (std::numeric_limits<_IntType>::digits + 31) / 32;
typedef typename _Select<(sizeof(unsigned) == 4),
unsigned, unsigned long>::_Type _UInt32Type;
typedef typename _To_Unsigned_Type<_IntType>::_Type
_UIntType;
const int __n = (std::numeric_limits<_UIntType>::digits + 31) / 32;
for (int __i = 0; __i < long_lag; ++__i)
{
......@@ -402,8 +373,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
_UIntType __factor = 1;
for (int __j = 0; __j < __n; ++__j)
{
__tmp += (__mod<_UInt32Type, 1, 0, 0>(__gen())
* __factor);
__tmp += __mod<_UInt32Type, 1, 0, 0>(__gen()) * __factor;
__factor *= _Shift<_UIntType, 32>::__value;
}
_M_x[__i] = __mod<_UIntType, 1, 0, modulus>(__tmp);
......@@ -423,7 +393,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
__ps += long_lag;
// Calculate new x(i) without overflow or division.
_IntType __xi;
// NB: Thanks to the requirements for _IntType, _M_x[_M_p] + _M_carry
// cannot overflow.
_UIntType __xi;
if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
{
__xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
......@@ -434,10 +406,10 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
__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)
if (++_M_p >= long_lag)
_M_p = 0;
return __xi;
......@@ -483,6 +455,134 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
}
template<typename _RealType, int __w, int __s, int __r>
void
subtract_with_carry_01<_RealType, __w, __s, __r>::
seed(unsigned long __value)
{
if (__value == 0)
__value = 19780503;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 512. Seeding subtract_with_carry_01 from a single unsigned long.
std::tr1::linear_congruential<unsigned long, 40014, 0, 2147483563>
__lcg(__value);
this->seed(__lcg);
}
template<typename _RealType, int __w, int __s, int __r>
template<class _Gen>
void
subtract_with_carry_01<_RealType, __w, __s, __r>::
seed(_Gen& __gen, false_type)
{
for (int __i = 0; __i < long_lag; ++__i)
{
for (int __j = 0; __j < __n - 1; ++__j)
_M_x[__i][__j] = __mod<_UInt32Type, 1, 0, 0>(__gen());
_M_x[__i][__n - 1] = __mod<_UInt32Type, 1, 0,
_Shift<_UInt32Type, __w % 32>::__value>(__gen());
}
_M_carry = (_M_x[long_lag - 1][0] == 0) ? 1 : 0;
_M_p = 0;
// Initialize the array holding the negative powers of 2.
for (int __j = 0; __j < __n; ++__j)
#if _GLIBCXX_USE_C99_MATH_TR1
_M_npows[__j] = std::tr1::ldexp(_RealType(1), -__w + __j * 32);
#else
_M_npows[__j] = std::pow(_RealType(2), -__w + __j * 32);
#endif
}
template<typename _RealType, int __w, int __s, int __r>
typename subtract_with_carry_01<_RealType, __w, __s, __r>::result_type
subtract_with_carry_01<_RealType, __w, __s, __r>::
operator()()
{
// Derive short lag index from current index.
int __ps = _M_p - short_lag;
if (__ps < 0)
__ps += long_lag;
_UInt32Type __new_carry;
for (int __j = 0; __j < __n - 1; ++__j)
{
if (_M_x[__ps][__j] > _M_x[_M_p][__j]
|| (_M_x[__ps][__j] == _M_x[_M_p][__j] && _M_carry == 0))
__new_carry = 0;
else
__new_carry = 1;
_M_x[_M_p][__j] = _M_x[__ps][__j] - _M_x[_M_p][__j] - _M_carry;
_M_carry = __new_carry;
}
if (_M_x[__ps][__n - 1] > _M_x[_M_p][__n - 1]
|| (_M_x[__ps][__n - 1] == _M_x[_M_p][__n - 1] && _M_carry == 0))
__new_carry = 0;
else
__new_carry = 1;
_M_x[_M_p][__n - 1] = __mod<_UInt32Type, 1, 0,
_Shift<_UInt32Type, __w % 32>::__value>
(_M_x[__ps][__n - 1] - _M_x[_M_p][__n - 1] - _M_carry);
_M_carry = __new_carry;
result_type __ret = 0.0;
for (int __j = 0; __j < __n; ++__j)
__ret += _M_x[_M_p][__j] * _M_npows[__j];
// Adjust current index to loop around in ring buffer.
if (++_M_p >= long_lag)
_M_p = 0;
return __ret;
}
template<typename _RealType, int __w, int __s, int __r,
typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const subtract_with_carry_01<_RealType, __w, __s, __r>& __x)
{
const std::ios_base::fmtflags __flags = __os.flags();
const _CharT __fill = __os.fill();
const _CharT __space = __os.widen(' ');
__os.flags(std::ios_base::dec | std::ios_base::fixed
| std::ios_base::left);
__os.fill(__space);
for (int __i = 0; __i < __r; ++__i)
for (int __j = 0; __j < __x.__n; ++__j)
__os << __x._M_x[__i][__j] << __space;
__os << __x._M_carry;
__os.flags(__flags);
__os.fill(__fill);
return __os;
}
template<typename _RealType, int __w, int __s, int __r,
typename _CharT, typename _Traits>
std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<_CharT, _Traits>& __is,
subtract_with_carry_01<_RealType, __w, __s, __r>& __x)
{
const std::ios_base::fmtflags __flags = __is.flags();
__is.flags(std::ios_base::dec | std::ios_base::skipws);
for (int __i = 0; __i < __r; ++__i)
for (int __j = 0; __j < __x.__n; ++__j)
__is >> __x._M_x[__i][__j];
__is >> __x._M_carry;
__is.flags(__flags);
return __is;
}
template<class _UniformRandomNumberGenerator, int __p, int __r>
typename discard_block<_UniformRandomNumberGenerator,
__p, __r>::result_type
......
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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_01 a;
for (int i = 0; i < 9999; ++i)
a();
#if _GLIBCXX_USE_C99_MATH_TR1
VERIFY( a() == 5957620 * std::tr1::ldexp(float(1), -24) );
#else
VERIFY( a() == 5957620 * std::pow(float(2), -24) );
#endif
}
int main()
{
test01();
return 0;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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_01 a;
for (int i = 0; i < 9999; ++i)
a();
#if _GLIBCXX_USE_C99_MATH_TR1
VERIFY( a() == 8587295 * std::tr1::ldexp(float(1), -24) );
#else
VERIFY( a() == 8587295 * std::pow(float(2), -24) );
#endif
}
int main()
{
test01();
return 0;
}
......@@ -30,7 +30,7 @@ test01()
bool test __attribute__((unused)) = true;
using namespace std::tr1;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x;
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> x;
VERIFY( x.min() == 0 );
VERIFY( x.max() == ((1<<24)-1) );
VERIFY( x() == 15039276 );
......
......@@ -38,7 +38,7 @@ test01()
bool test __attribute__((unused)) = true;
using namespace std::tr1;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x(gen);
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> x(gen);
VERIFY( x.min() == 0 );
VERIFY( x.max() == ((1 << 24) - 1) );
}
......
......@@ -30,7 +30,7 @@ test01()
using namespace std::tr1;
unsigned long seed = 2;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x(seed);
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> x(seed);
}
int main()
......
......@@ -31,7 +31,7 @@ test01()
using namespace std::tr1;
double seed = 2.0;
subtract_with_carry<unsigned long, (1 << 24), 10, 24> x(seed);
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> x(seed);
}
int main()
......
......@@ -30,8 +30,8 @@ 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;
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> u;
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> v;
VERIFY( u == v );
......
......@@ -30,8 +30,8 @@ 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);
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> u(1);
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> v(2);
VERIFY( u != v );
}
......
......@@ -32,8 +32,8 @@ test01()
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;
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> u;
subtract_with_carry<unsigned long, (1UL << 24), 10, 24> v;
u(); // advance
str << u;
......
......@@ -28,7 +28,8 @@
void
test01()
{
typedef std::tr1::subtract_with_carry<long, 8, 2, 4> test_type;
typedef std::tr1::subtract_with_carry<unsigned long, (1UL << 24), 10, 24>
test_type;
typedef test_type::result_type result_type;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 class template subtract_with_carry_01 [tr.rand.eng.sub1]
// 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_01<float, 24, 10, 24> x;
VERIFY( x.min() == 0.0 );
VERIFY( x.max() == 1.0 );
#if _GLIBCXX_USE_C99_MATH_TR1
VERIFY( x() == 15039276 * std::tr1::ldexp(float(1), -24) );
#else
VERIFY( x() == 15039276 * std::pow(float(2), -24) );
#endif
}
int main()
{
test01();
return 0;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 class template subtract_with_carry_01 [tr.rand.eng.sub1]
// 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_01<float, 24, 10, 24> x(gen);
VERIFY( x.min() == 0.0 );
VERIFY( x.max() == 1.0 );
}
int main()
{
test01();
return 0;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 class template subtract_with_carry_01 [tr.rand.eng.sub1]
// 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_01<float, 24, 10, 24> x(seed);
}
int main()
{
test01();
return 0;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 class template subtract_with_carry_01 [tr.rand.eng.sub1]
// 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_01<float, 24, 10, 24> x(seed);
}
int main()
{
test01();
return 0;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 class template subtract_with_carry_01 [tr.rand.eng.sub1]
// 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_01<float, 24, 10, 24> u;
subtract_with_carry_01<float, 24, 10, 24> v;
VERIFY( u == v );
for (int i = 0; i < 100; ++i)
{
u();
v();
}
VERIFY( u == v );
}
int main()
{
test01();
return 0;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 class template subtract_with_carry_01 [tr.rand.eng.sub1]
// 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_01<float, 24, 10, 24> u(1);
subtract_with_carry_01<float, 24, 10, 24> v(2);
VERIFY( u != v );
}
int main()
{
test01();
return 0;
}
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 class template subtract_with_carry_01 [tr.rand.eng.sub1]
// 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_01;
std::stringstream str;
subtract_with_carry_01<float, 24, 10, 24> u;
subtract_with_carry_01<float, 24, 10, 24> v;
u(); // advance
str << u;
VERIFY( u != v );
str >> v;
VERIFY( u == v );
}
int main()
{
test01();
return 0;
}
// { dg-do compile }
//
// 2006-08-22 Paolo Carlini <pcarlini@suse.de>
//
// 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.4 Class template subtract_with_carry_01
// 5.1.1 [1] Table 15
#include <tr1/random>
void
test01()
{
typedef std::tr1::subtract_with_carry_01<float, 24, 10, 24> test_type;
typedef test_type::result_type result_type;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment