From: paolo Date: Mon, 19 Jun 2006 16:03:07 +0000 (+0000) Subject: 2006-06-19 Paolo Carlini X-Git-Tag: upstream/4.9.2~54041 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b463950830cbaf1767a8e1dce5f82feb5e8cb0f5;p=platform%2Fupstream%2Flinaro-gcc.git 2006-06-19 Paolo Carlini * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114777 138bc75d-0d04-0410-961f-82ee72b054a4 --- 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 + + * 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 Paolo Carlini 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 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 +// +// 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 +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::tr1; + + discard_block + < + subtract_with_carry, + 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 +// +// 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 +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std::tr1; + + discard_block + < + subtract_with_carry, + 389, 24 + > u(1); + + discard_block + < + subtract_with_carry, + 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 +// +// 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 +#include +#include + +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, + 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 +// +// 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 +#include + +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 +// +// 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 +#include + +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 +// +// 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 +#include +#include + +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; +}