aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2006-06-07 01:50:09 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2006-06-07 01:50:09 +0000
commitd95c1c488a438af4c077b2f8eb1e940199e98e59 (patch)
tree511bd30e94a3058c98d5449b7fa65b91011948a3 /libstdc++-v3
parentefbd5a9431f64cc195581c1f4f407b3c93f7c1ff (diff)
downloadgcc-d95c1c488a438af4c077b2f8eb1e940199e98e59.zip
gcc-d95c1c488a438af4c077b2f8eb1e940199e98e59.tar.gz
gcc-d95c1c488a438af4c077b2f8eb1e940199e98e59.tar.bz2
random (mersenne_twister<>::operator==, [...]): Implement.
2006-06-06 Paolo Carlini <pcarlini@suse.de> * include/tr1/random (mersenne_twister<>::operator==, operator!=, operator<<, operator>>): Implement. * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/ operators/equal.cc: New. * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/ operators/not_equal.cc: Likewise. * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/ operators/serialize.cc: Likewise. * include/tr1/random (subtract_with_carry<>::operator==): Fix, compare the whole state; use std::equal. * include/tr1/random: Minor formatting and style changes. From-SVN: r114459
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog16
-rw-r--r--libstdc++-v3/include/tr1/random172
-rw-r--r--libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/equal.cc53
-rw-r--r--libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/not_equal.cc52
-rw-r--r--libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/serialize.cc54
5 files changed, 293 insertions, 54 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index ac1cb54..4340500 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,19 @@
+2006-06-06 Paolo Carlini <pcarlini@suse.de>
+
+ * include/tr1/random (mersenne_twister<>::operator==,
+ operator!=, operator<<, operator>>): Implement.
+ * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/
+ operators/equal.cc: New.
+ * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/
+ operators/not_equal.cc: Likewise.
+ * testsuite/tr1/5_numerical_facilities/random/mersenne_twister/
+ operators/serialize.cc: Likewise.
+
+ * include/tr1/random (subtract_with_carry<>::operator==): Fix,
+ compare the whole state; use std::equal.
+
+ * include/tr1/random: Minor formatting and style changes.
+
2006-06-06 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/tr1/5_numerical_facilies: Move to...
diff --git a/libstdc++-v3/include/tr1/random b/libstdc++-v3/include/tr1/random
index a018a83..7bdf8e6 100644
--- a/libstdc++-v3/include/tr1/random
+++ b/libstdc++-v3/include/tr1/random
@@ -517,6 +517,76 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
result_type
operator()();
+ /**
+ * Compares two % mersenne_twister random number generator objects of
+ * the same type for equality.
+ *
+ * @param __lhs A % mersenne_twister random number generator object.
+ * @param __rhs Another % mersenne_twister random number generator
+ * object.
+ *
+ * @returns true if the two objects are equal, false otherwise.
+ */
+ friend bool
+ operator==(const mersenne_twister& __lhs,
+ const mersenne_twister& __rhs)
+ { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
+
+ /**
+ * Compares two % mersenne_twister random number generator objects of
+ * the same type for inequality.
+ *
+ * @param __lhs A % mersenne_twister random number generator object.
+ * @param __rhs Another % mersenne_twister random number generator
+ * object.
+ *
+ * @returns true if the two objects are not equal, false otherwise.
+ */
+ friend bool
+ operator!=(const mersenne_twister& __lhs,
+ const mersenne_twister& __rhs)
+ { return !(__lhs == __rhs); }
+
+ /**
+ * Inserts the current state of a % mersenne_twister random number
+ * generator engine @p __x into the output stream @p __os.
+ *
+ * @param __os An output stream.
+ * @param __x A % mersenne_twister random number generator engine.
+ *
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __os,
+ const mersenne_twister& __x)
+ {
+ std::copy(__x._M_x, __x._M_x + state_size,
+ std::ostream_iterator<_UIntType>(__os, " "));
+ return __os;
+ }
+
+ /**
+ * Extracts the current state of a % mersenne_twister random number
+ * generator engine @p __x from the input stream @p __is.
+ *
+ * @param __is An input stream.
+ * @param __x A % mersenne_twister random number generator engine.
+ *
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
+ */
+ template<typename _CharT, typename _Traits>
+ friend basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __is,
+ mersenne_twister& __x)
+ {
+ for (int __i = 0; __i < state_size; ++__i)
+ __is >> __x._M_x[__i];
+ return __is;
+ }
+
private:
template<class _Gen>
void
@@ -669,10 +739,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
friend bool
operator==(const subtract_with_carry& __lhs,
const subtract_with_carry& __rhs)
- {
- return ((__lhs._M_x[0] == __rhs._M_x[0])
- && (__lhs._M_x[__r - 1] == __rhs._M_x[__r - 1]));
- }
+ { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
/**
* Compares two % subtract_with_carry random number generator objects of
@@ -691,40 +758,40 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a % subtract_with_carry random number
- * genator engine @p x into the output stream @p __os.
+ * generator engine @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A % subtract_with_carry random number generator engine.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
const subtract_with_carry& __x)
{
- std::copy(__x._M_x, __x._M_x + __r,
+ std::copy(__x._M_x, __x._M_x + long_lag,
std::ostream_iterator<_IntType>(__os, " "));
return __os << __x._M_carry;
}
/**
* Extracts the current state of a % subtract_with_carry random number
- * gerator engine @p x from the input stream @p __is.
+ * generator engine @p __x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A % subtract_with_carry random number generator engine.
*
- * @returns The input stream with the state of @p x extracted or in an
- * error state.
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
subtract_with_carry& __x)
{
- for (int __i = 0; __i < __r; ++__i)
+ for (int __i = 0; __i < long_lag; ++__i)
__is >> __x._M_x[__i];
__is >> __x._M_carry;
return __is;
@@ -865,10 +932,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
*/
friend bool
operator==(const discard_block& __lhs, const discard_block& __rhs)
- {
- return ((__lhs._M_b == __rhs._M_b)
- && (__lhs._M_n == __rhs._M_n));
- }
+ { return (__lhs._M_b == __rhs._M_b) && (__lhs._M_n == __rhs._M_n); }
/**
* Compares two %discard_block random number generator objects of
@@ -886,13 +950,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a %discard_block random number
- * genator engine @p x into the output stream @p __os.
+ * generator engine @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %discard_block random number generator engine.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -902,13 +966,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts the current state of a % subtract_with_carry random number
- * gerator engine @p x from the input stream @p __is.
+ * generator engine @p __x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A %discard_block random number generator engine.
*
- * @returns The input stream with the state of @p x extracted or in an
- * error state.
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1035,7 +1099,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator==(const xor_combine& __lhs, const xor_combine& __rhs)
{
return (__lhs.base1() == __rhs.base1())
- && (__lhs.base2() == __rhs.base2());
+ && (__lhs.base2() == __rhs.base2());
}
/**
@@ -1054,13 +1118,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts the current state of a %xor_combine random number
- * genator engine @p x into the output stream @p __os.
+ * generator engine @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %xor_combine random number generator engine.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1070,13 +1134,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts the current state of a %xor_combine random number
- * gerator engine @p x from the input stream @p __is.
+ * generator engine @p __x from the input stream @p __is.
*
* @param __is An input stream.
* @param __x A %xor_combine random number generator engine.
*
- * @returns The input stream with the state of @p x extracted or in an
- * error state.
+ * @returns The input stream with the state of @p __x extracted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1199,14 +1263,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return __urng() % __n; }
/**
- * Inserts a %uniform_int random number distribution @p x into the
+ * Inserts a %uniform_int random number distribution @p __x into the
* output stream @p os.
*
* @param __os An output stream.
* @param __x A %uniform_int random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1216,12 +1280,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %unform_int random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %uniform_int random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1303,13 +1367,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %bernoulli_distribution random number distribution
- * @p x into the output stream @p __os.
+ * @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %bernoulli_distribution random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1319,12 +1383,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %bernoulli_distribution random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %bernoulli_distribution random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1393,13 +1457,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %geometric_distribution random number distribution
- * @p x into the output stream @p __os.
+ * @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %geometric_distribution random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1409,12 +1473,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %geometric_distribution random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %geometric_distribution random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1479,14 +1543,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ return (__urng() * (max() - min())) + min(); }
/**
- * Inserts a %uniform_real random number distribution @p x into the
+ * Inserts a %uniform_real random number distribution @p __x into the
* output stream @p __os.
*
* @param __os An output stream.
* @param __x A %uniform_real random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1496,12 +1560,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %unform_real random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %uniform_real random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
@@ -1569,13 +1633,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Inserts a %exponential_distribution random number distribution
- * @p x into the output stream @p __os.
+ * @p __x into the output stream @p __os.
*
* @param __os An output stream.
* @param __x A %exponential_distribution random number distribution.
*
- * @returns The output stream with the state of @p x inserted or in an
- * error state.
+ * @returns The output stream with the state of @p __x inserted or in
+ * an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_ostream<_CharT, _Traits>&
@@ -1585,12 +1649,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/**
* Extracts a %exponential_distribution random number distribution
- * @p u from the input stream @p __is.
+ * @p __u from the input stream @p __is.
*
* @param __is An input stream.
* @param __u A %exponential_distribution random number generator engine.
*
- * @returns The input stream with @p u extracted or in an error state.
+ * @returns The input stream with @p __u extracted or in an error state.
*/
template<typename _CharT, typename _Traits>
friend basic_istream<_CharT, _Traits>&
diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/equal.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/equal.cc
new file mode 100644
index 0000000..2cecdb6
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/equal.cc
@@ -0,0 +1,53 @@
+// 2006-06-06 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.2 class template mersenne_twister [tr.rand.eng.mers]
+// 5.1.1 Table 16
+
+#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> 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/mersenne_twister/operators/not_equal.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/not_equal.cc
new file mode 100644
index 0000000..08252ce
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/not_equal.cc
@@ -0,0 +1,52 @@
+// 2006-06-06 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.2 class template mersenne_twister [tr.rand.eng.mers]
+// 5.1.1 Table 16
+
+#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> u(1);
+
+ mersenne_twister<
+ unsigned long, 32, 624, 397, 31,
+ 0x9908b0dful, 11, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18> v(2);
+
+ VERIFY( u != v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/serialize.cc b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/serialize.cc
new file mode 100644
index 0000000..a862e3c
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/mersenne_twister/operators/serialize.cc
@@ -0,0 +1,54 @@
+// 2006-06-06 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.2 class template mersenne_twister [tr.rand.eng.mers]
+// 5.1.1 Table 16
+
+#include <sstream>
+#include <tr1/random>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::mersenne_twister;
+
+ std::stringstream str;
+ mersenne_twister<
+ unsigned long, 32, 624, 397, 31,
+ 0x9908b0dful, 11, 7,
+ 0x9d2c5680ul, 15,
+ 0xefc60000ul, 18> u, v;
+
+ u(); // advance
+ str << u;
+
+ VERIFY( u != v );
+
+ str >> v;
+ VERIFY( u == v );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}