diff options
author | Paolo Carlini <pcarlini@suse.de> | 2006-06-19 16:03:07 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2006-06-19 16:03:07 +0000 |
commit | 3c618f8732814407a5c98146fa24761ba7dddd78 (patch) | |
tree | dfa086017c9dd38936ecf97ec423c0df48ff3287 /libstdc++-v3 | |
parent | 7ed9c0015f129b4abf51c241f6dec346120088e1 (diff) | |
download | gcc-3c618f8732814407a5c98146fa24761ba7dddd78.zip gcc-3c618f8732814407a5c98146fa24761ba7dddd78.tar.gz gcc-3c618f8732814407a5c98146fa24761ba7dddd78.tar.bz2 |
random (xor_combine<>::operator<<): Fix typo.
2006-06-19 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (xor_combine<>::operator<<): Fix typo.
* include/tr1/random (bernoulli_distribution::min(),
bernoulli_distribution::max(), geometric_distribution<>::min(),
geometric_distribution<>::max()): Remove.
* include/tr1/random (geometric_distribution<>::operator()):
Simplify formula.
* include/tr1/random: Minor cosmetic changes.
* testsuite/tr1/5_numerical_facilities/random/discard_block/
operators/equal.cc: New.
* testsuite/tr1/5_numerical_facilities/random/discard_block/
operators/not_equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/discard_block/
operators/serialize.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/xor_combine/
operators/equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/xor_combine/
operators/not_equal.cc: Likewise.
* testsuite/tr1/5_numerical_facilities/random/xor_combine/
operators/serialize.cc: Likewise.
From-SVN: r114777
Diffstat (limited to 'libstdc++-v3')
8 files changed, 357 insertions, 37 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7ed9724..d01182b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,29 @@ +2006-06-19 Paolo Carlini <pcarlini@suse.de> + + * include/tr1/random (xor_combine<>::operator<<): Fix typo. + + * include/tr1/random (bernoulli_distribution::min(), + bernoulli_distribution::max(), geometric_distribution<>::min(), + geometric_distribution<>::max()): Remove. + + * include/tr1/random (geometric_distribution<>::operator()): + Simplify formula. + + * include/tr1/random: Minor cosmetic changes. + + * testsuite/tr1/5_numerical_facilities/random/discard_block/ + operators/equal.cc: New. + * testsuite/tr1/5_numerical_facilities/random/discard_block/ + operators/not_equal.cc: Likewise. + * testsuite/tr1/5_numerical_facilities/random/discard_block/ + operators/serialize.cc: Likewise. + * testsuite/tr1/5_numerical_facilities/random/xor_combine/ + operators/equal.cc: Likewise. + * testsuite/tr1/5_numerical_facilities/random/xor_combine/ + operators/not_equal.cc: Likewise. + * testsuite/tr1/5_numerical_facilities/random/xor_combine/ + operators/serialize.cc: Likewise. + 2006-06-17 Ami Tavory <atavory@gmail.com> Paolo Carlini <pcarlini@suse.de> diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random index 0f4ab01..69bda57 100644 --- a/libstdc++-v3/include/tr1/random +++ b/libstdc++-v3/include/tr1/random @@ -840,7 +840,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) /** * Constructs a default %discard_block engine. * - * The underlying engine is default constrcuted as well. + * The underlying engine is default constructed as well. */ discard_block() : _M_n(0) { } @@ -851,8 +851,9 @@ _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. @@ -860,7 +861,8 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) * 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) + explicit + discard_block(unsigned long __s) : _M_b(__s), _M_n(0) { } /** @@ -1135,7 +1137,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, const xor_combine& __x) - { return __os << __x.base1() << " " << __x.base1(); } + { return __os << __x.base1() << " " << __x.base2(); } /** * Extracts the current state of a %xor_combine random number @@ -1344,7 +1346,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, const uniform_int& __x) - { return __os << __x._M_min << " " << __x._M_max; } + { return __os << __x.min() << " " << __x.max(); } /** * Extracts a %unform_int random number distribution @@ -1400,20 +1402,6 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) { return _M_p; } /** - * Gets the inclusive lower bound of the distribution range. - */ - result_type - min() const - { return false; } - - /** - * Gets the inclusive upper bound of the distribution range. - */ - result_type - max() const - { return true; } - - /** * Resets the distribution state. * * Does nothing for a bernoulli distribution. @@ -1500,28 +1488,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) p() const { return _M_p; } - /** - * Gets the inclusive lower bound of the distribution range. - */ - result_type - min() const; - - /** - * Gets the inclusive upper bound of the distribution range. - */ - result_type - max() const; - void reset() { } template<class _UniformRandomNumberGenerator> result_type operator()(_UniformRandomNumberGenerator& __urng) - { - return result_type(std::floor(std::log(_RealType(1.0) - __urng()) - / _M_log_p)) + result_type(1); - } + { return result_type(std::ceil(std::log(__urng()) / _M_log_p)); } /** * Inserts a %geometric_distribution random number distribution @@ -1631,7 +1604,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) friend std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& __os, const uniform_real& __x) - { return __os << __x._M_min << " " << __x._M_max; } + { return __os << __x.min() << " " << __x.max(); } /** * Extracts a %unform_real random number distribution diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/equal.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/equal.cc new file mode 100644 index 0000000..55c02da --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/equal.cc @@ -0,0 +1,53 @@ +// 2006-06-19 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.5 class template discard_block [tr.rand.eng.disc] +// 5.1.1 Table 16 + +#include <tr1/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::tr1; + + discard_block + < + subtract_with_carry<long, (1 << 24), 10, 24>, + 389, 24 + > u, v; + + VERIFY( u == v ); + + for (int i = 0; i < 100; ++i) + { + u(); + v(); + } + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/not_equal.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/not_equal.cc new file mode 100644 index 0000000..0b52507 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/not_equal.cc @@ -0,0 +1,52 @@ +// 2006-06-19 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.5 class template discard_block [tr.rand.eng.disc] +// 5.1.1 Table 16 + +#include <tr1/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::tr1; + + discard_block + < + subtract_with_carry<long, (1 << 24), 10, 24>, + 389, 24 + > u(1); + + discard_block + < + subtract_with_carry<long, (1 << 24), 10, 24>, + 389, 24 + > v(2); + + VERIFY( u != v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/serialize.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/serialize.cc new file mode 100644 index 0000000..8127daa --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/discard_block/operators/serialize.cc @@ -0,0 +1,55 @@ +// 2006-06-19 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.5 class template discard_block [tr.rand.eng.disc] +// 5.1.1 Table 16 + +#include <sstream> +#include <tr1/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::discard_block; + using std::tr1::subtract_with_carry; + + std::stringstream str; + discard_block + < + subtract_with_carry<long, (1 << 24), 10, 24>, + 389, 24 + > u, v; + + u(); // advance + str << u; + + VERIFY( u != v ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/equal.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/equal.cc new file mode 100644 index 0000000..8de8422 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/equal.cc @@ -0,0 +1,53 @@ +// 2006-06-19 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.6 class template xor_combine [tr.rand.eng.xor] +// 5.1.1 Table 16 + +#include <tr1/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::tr1; + + xor_combine + < + minstd_rand, 1, + mt19937, 2 + > u, v; + + VERIFY( u == v ); + + for (int i = 0; i < 100; ++i) + { + u(); + v(); + } + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/not_equal.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/not_equal.cc new file mode 100644 index 0000000..994f4d3 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/not_equal.cc @@ -0,0 +1,52 @@ +// 2006-06-19 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.6 class template discard_block [tr.rand.eng.xor] +// 5.1.1 Table 16 + +#include <tr1/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::tr1; + + xor_combine + < + minstd_rand, 1, + mt19937, 2 + > u(1); + + xor_combine + < + minstd_rand, 1, + mt19937, 2 + > v(2); + + VERIFY( u != v ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/serialize.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/serialize.cc new file mode 100644 index 0000000..dd92089 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/xor_combine/operators/serialize.cc @@ -0,0 +1,56 @@ +// 2006-06-19 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.6 class template xor_combine [tr.rand.eng.xor] +// 5.1.1 Table 16 + +#include <sstream> +#include <tr1/random> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::xor_combine; + using std::tr1::minstd_rand; + using std::tr1::mt19937; + + std::stringstream str; + xor_combine + < + minstd_rand, 1, + mt19937, 2 + > u, v; + + u(); // advance + str << u; + + VERIFY( u != v ); + + str >> v; + VERIFY( u == v ); +} + +int main() +{ + test01(); + return 0; +} |