diff --git a/libstdc++-v3/include/ext/random b/libstdc++-v3/include/ext/random index 0207d392261..adf8a241187 100644 --- a/libstdc++-v3/include/ext/random +++ b/libstdc++-v3/include/ext/random @@ -1856,6 +1856,473 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const k_distribution<_RealType>& __d2) { return !(__d1 == __d2); } + + /** + * @brief An arcsine continuous distribution for random numbers. + * + * The formula for the arcsine probability density function is + * @f[ + * p(x|a,b) = \frac{1}{\pi \sqrt{(x - a)(b - x)}} + * @f] + * where @f$x >= a@f$ and @f$x <= b@f$. + * + * + * + * + * + * + *
Distribution Statistics
Mean@f$ (a + b) / 2 @f$
Variance@f$ (b - a)^2 / 8 @f$
Range@f$[a, b]@f$
+ */ + template + class + arcsine_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef arcsine_distribution distribution_type; + + param_type(result_type __a = result_type(0), + result_type __b = result_type(1)) + : _M_a(__a), _M_b(__b) + { + _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b); + } + + result_type + a() const + { return _M_a; } + + result_type + b() const + { return _M_b; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_a == __p2._M_a && __p1._M_b == __p2._M_b; } + + private: + void _M_initialize(); + + result_type _M_a; + result_type _M_b; + }; + + /** + * @brief Constructors. + */ + explicit + arcsine_distribution(result_type __a = result_type(0), + result_type __b = result_type(1)) + : _M_param(__a, __b), + _M_ud(-1.5707963267948966192313216916397514L, + +1.5707963267948966192313216916397514L) + { } + + explicit + arcsine_distribution(const param_type& __p) + : _M_param(__p), + _M_ud(-1.5707963267948966192313216916397514L, + +1.5707963267948966192313216916397514L) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { _M_ud.reset(); } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + a() const + { return _M_param.a(); } + + result_type + b() const + { return _M_param.b(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return this->a(); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return this->b(); } + + /** + * @brief Generating functions. + */ + template + result_type + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x = std::sin(this->_M_ud(__urng)); + return (__x * (this->b() - this->a()) + + this->a() + this->b()) / result_type(2); + } + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + result_type __x = std::sin(this->_M_ud(__urng)); + return (__x * (__p.b() - __p.a()) + + __p.a() + __p.b()) / result_type(2); + } + + template + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, this->param()); } + + template + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two arcsine distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const arcsine_distribution& __d1, + const arcsine_distribution& __d2) + { return (__d1.param() == __d2.param() + && __d1._M_ud == __d2._M_ud); } + + /** + * @brief Inserts a %arcsine_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %arcsine_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const arcsine_distribution<_RealType1>&); + + /** + * @brief Extracts a %arcsine_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %arcsine_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + arcsine_distribution<_RealType1>&); + + private: + template + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + std::uniform_real_distribution _M_ud; + }; + + /** + * @brief Return true if two arcsine distributions are not equal. + */ + template + inline bool + operator!=(const arcsine_distribution<_RealType>& __d1, + const arcsine_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + + + /** + * @brief A Hoyt continuous distribution for random numbers. + * + * The formula for the Hoyt probability density function is + * @f[ + * p(x|q,\omega) = \frac{(1 + q^2)x}{q\omega} + * \exp\left(-\frac{(1 + q^2)^2 x^2}{4 q^2 \omega}\right) + * I_0\left(\frac{(1 - q^4) x^2}{4 q^2 \omega}\right) + * @f] + * where @f$I_0(z)@f$ is the modified Bessel function of the first kind + * of order 0 and @f$0 < q < 1@f$. + * + * + * + * + * + * + *
Distribution Statistics
Mean@f$ \sqrt{\frac{2}{\pi}} \sqrt{\frac{\omega}{1 + q^2}} + * E(1 - q^2) @f$
Variance@f$ \omega \left(1 - \frac{2E^2(1 - q^2)} + * {\pi (1 + q^2)}\right) @f$
Range@f$[0, \infty)@f$
+ * where @f$E(x)@f$ is the elliptic function of the second kind. + */ + template + class + hoyt_distribution + { + static_assert(std::is_floating_point<_RealType>::value, + "template argument not a floating point type"); + + public: + /** The type of the range of the distribution. */ + typedef _RealType result_type; + /** Parameter type. */ + struct param_type + { + typedef hoyt_distribution distribution_type; + + param_type(result_type __q = result_type(0.5L), + result_type __omega = result_type(1)) + : _M_q(__q), _M_omega(__omega) + { + _GLIBCXX_DEBUG_ASSERT(_M_q > result_type(0)); + _GLIBCXX_DEBUG_ASSERT(_M_q < result_type(1)); + } + + result_type + q() const + { return _M_q; } + + result_type + omega() const + { return _M_omega; } + + friend bool + operator==(const param_type& __p1, const param_type& __p2) + { return __p1._M_q == __p2._M_q + && __p1._M_omega == __p2._M_omega; } + + private: + void _M_initialize(); + + result_type _M_q; + result_type _M_omega; + }; + + /** + * @brief Constructors. + */ + explicit + hoyt_distribution(result_type __q = result_type(0.5L), + result_type __omega = result_type(1)) + : _M_param(__q, __omega), + _M_ad(result_type(0.5L) * (result_type(1) + __q * __q), + result_type(0.5L) * (result_type(1) + __q * __q) + / (__q * __q)), + _M_ed(result_type(1)) + { } + + explicit + hoyt_distribution(const param_type& __p) + : _M_param(__p), + _M_ad(result_type(0.5L) * (result_type(1) + __p.q() * __p.q()), + result_type(0.5L) * (result_type(1) + __p.q() * __p.q()) + / (__p.q() * __p.q())), + _M_ed(result_type(1)) + { } + + /** + * @brief Resets the distribution state. + */ + void + reset() + { + _M_ad.reset(); + _M_ed.reset(); + } + + /** + * @brief Return the parameters of the distribution. + */ + result_type + q() const + { return _M_param.q(); } + + result_type + omega() const + { return _M_param.omega(); } + + /** + * @brief Returns the parameter set of the distribution. + */ + param_type + param() const + { return _M_param; } + + /** + * @brief Sets the parameter set of the distribution. + * @param __param The new parameter set of the distribution. + */ + void + param(const param_type& __param) + { _M_param = __param; } + + /** + * @brief Returns the greatest lower bound value of the distribution. + */ + result_type + min() const + { return result_type(0); } + + /** + * @brief Returns the least upper bound value of the distribution. + */ + result_type + max() const + { return std::numeric_limits::max(); } + + /** + * @brief Generating functions. + */ + template + result_type + operator()(_UniformRandomNumberGenerator& __urng); + + template + result_type + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p); + + template + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng) + { this->__generate(__f, __t, __urng, this->param()); } + + template + void + __generate(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + template + void + __generate(result_type* __f, result_type* __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { this->__generate_impl(__f, __t, __urng, __p); } + + /** + * @brief Return true if two Hoyt distributions have + * the same parameters and the sequences that would + * be generated are equal. + */ + friend bool + operator==(const hoyt_distribution& __d1, + const hoyt_distribution& __d2) + { return (__d1.param() == __d2.param() + && __d1._M_ad == __d2._M_ad + && __d1._M_ed == __d2._M_ed); } + + /** + * @brief Inserts a %hoyt_distribution random number distribution + * @p __x into the output stream @p __os. + * + * @param __os An output stream. + * @param __x A %hoyt_distribution random number distribution. + * + * @returns The output stream with the state of @p __x inserted or in + * an error state. + */ + template + friend std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>&, + const hoyt_distribution<_RealType1>&); + + /** + * @brief Extracts a %hoyt_distribution random number distribution + * @p __x from the input stream @p __is. + * + * @param __is An input stream. + * @param __x A %hoyt_distribution random number + * generator engine. + * + * @returns The input stream with @p __x extracted or in an error state. + */ + template + friend std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>&, + hoyt_distribution<_RealType1>&); + + private: + template + void + __generate_impl(_ForwardIterator __f, _ForwardIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p); + + param_type _M_param; + + __gnu_cxx::arcsine_distribution _M_ad; + std::exponential_distribution _M_ed; + }; + + /** + * @brief Return true if two Hoyt distributions are not equal. + */ + template + inline bool + operator!=(const hoyt_distribution<_RealType>& __d1, + const hoyt_distribution<_RealType>& __d2) + { return !(__d1 == __d2); } + _GLIBCXX_END_NAMESPACE_VERSION } // namespace __gnu_cxx diff --git a/libstdc++-v3/include/ext/random.tcc b/libstdc++-v3/include/ext/random.tcc index a196f74bdc4..ba6aaf2e111 100644 --- a/libstdc++-v3/include/ext/random.tcc +++ b/libstdc++-v3/include/ext/random.tcc @@ -1015,6 +1015,178 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __is; } + + template + template + void + arcsine_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + result_type __dif = __p.b() - __p.a(); + result_type __sum = __p.a() + __p.b(); + while (__f != __t) + { + result_type __x = std::sin(this->_M_ud(__urng)); + *__f++ = (__x * __dif + __sum) / result_type(2); + } + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const arcsine_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.a() << __space << __x.b(); + __os << __space << __x._M_ud; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + arcsine_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __a, __b; + __is >> __a >> __b; + __is >> __x._M_ud; + __x.param(typename arcsine_distribution<_RealType>:: + param_type(__a, __b)); + + __is.flags(__flags); + return __is; + } + + + template + template + typename hoyt_distribution<_RealType>::result_type + hoyt_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng) + { + result_type __x = this->_M_ad(__urng); + result_type __y = this->_M_ed(__urng); + return (result_type(2) * this->q() + / (result_type(1) + this->q() * this->q())) + * std::sqrt(this->omega() * __x * __y); + } + + template + template + typename hoyt_distribution<_RealType>::result_type + hoyt_distribution<_RealType>:: + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + result_type __q2 = __p.q() * __p.q(); + result_type __num = result_type(0.5L) * (result_type(1) + __q2); + typename __gnu_cxx::arcsine_distribution::param_type + __pa(__num, __num / __q2); + result_type __x = this->_M_ad(__pa, __urng); + result_type __y = this->_M_ed(__urng); + return (result_type(2) * __p.q() / (result_type(1) + __q2)) + * std::sqrt(__p.omega() * __x * __y); + } + + template + template + void + hoyt_distribution<_RealType>:: + __generate_impl(_OutputIterator __f, _OutputIterator __t, + _UniformRandomNumberGenerator& __urng, + const param_type& __p) + { + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator>) + + result_type __2q = result_type(2) * __p.q(); + result_type __q2 = __p.q() * __p.q(); + result_type __q2p1 = result_type(1) + __q2; + result_type __num = result_type(0.5L) * __q2p1; + result_type __omega = __p.omega(); + typename __gnu_cxx::arcsine_distribution::param_type + __pa(__num, __num / __q2); + while (__f != __t) + { + result_type __x = this->_M_ad(__pa, __urng); + result_type __y = this->_M_ed(__urng); + *__f++ = (__2q / __q2p1) * std::sqrt(__omega * __x * __y); + } + } + + template + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, + const hoyt_distribution<_RealType>& __x) + { + typedef std::basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __os.flags(); + const _CharT __fill = __os.fill(); + const std::streamsize __precision = __os.precision(); + const _CharT __space = __os.widen(' '); + __os.flags(__ios_base::scientific | __ios_base::left); + __os.fill(__space); + __os.precision(std::numeric_limits<_RealType>::max_digits10); + + __os << __x.q() << __space << __x.omega(); + __os << __space << __x._M_ad; + __os << __space << __x._M_ed; + + __os.flags(__flags); + __os.fill(__fill); + __os.precision(__precision); + return __os; + } + + template + std::basic_istream<_CharT, _Traits>& + operator>>(std::basic_istream<_CharT, _Traits>& __is, + hoyt_distribution<_RealType>& __x) + { + typedef std::basic_istream<_CharT, _Traits> __istream_type; + typedef typename __istream_type::ios_base __ios_base; + + const typename __ios_base::fmtflags __flags = __is.flags(); + __is.flags(__ios_base::dec | __ios_base::skipws); + + _RealType __q, __omega; + __is >> __q >> __omega; + __is >> __x._M_ad; + __is >> __x._M_ed; + __x.param(typename hoyt_distribution<_RealType>:: + param_type(__q, __omega)); + + __is.flags(__flags); + return __is; + } + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/testsuite/ext/random/arcsine_distribution/cons/default.cc b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/cons/default.cc new file mode 100644 index 00000000000..c149bd08fc9 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/cons/default.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::arcsine_distribution<> u; + VERIFY( u.a() == 0.0 ); + VERIFY( u.b() == 1.0 ); + VERIFY( u.min() == 0.0 ); + VERIFY( u.max() == 1.0 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/arcsine_distribution/cons/parms.cc b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/cons/parms.cc new file mode 100644 index 00000000000..50c5cb2c9b5 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/cons/parms.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::arcsine_distribution<> u(-1.5, 3.0); + VERIFY( u.a() == -1.5 ); + VERIFY( u.b() == 3.0 ); + VERIFY( u.min() == -1.5 ); + VERIFY( u.max() == 3.0 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/equal.cc b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/equal.cc new file mode 100644 index 00000000000..210ac1a91eb --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/equal.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::arcsine_distribution u(-2.0, 3.0), v, w; + + VERIFY( v == w ); + VERIFY( !(u == v) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/inequal.cc b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/inequal.cc new file mode 100644 index 00000000000..fba59052e5d --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/inequal.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::arcsine_distribution u(-2.0, 3.0), v, w; + + VERIFY( u != v ); + VERIFY( !(v != w) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/serialize.cc new file mode 100644 index 00000000000..7cbed402f17 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/operators/serialize.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + __gnu_cxx::arcsine_distribution u(-1.5, 3.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + str >> v; + VERIFY( u == v ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/arcsine_distribution/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/requirements/explicit_instantiation/1.cc new file mode 100644 index 00000000000..102b22f9df5 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/requirements/explicit_instantiation/1.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include + +template class __gnu_cxx::arcsine_distribution; +template class __gnu_cxx::arcsine_distribution; +template class __gnu_cxx::arcsine_distribution; diff --git a/libstdc++-v3/testsuite/ext/random/arcsine_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..b4a79403922 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/arcsine_distribution/requirements/typedefs.cc @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include + +void +test01() +{ + typedef __gnu_cxx::arcsine_distribution test_type; + + typedef test_type::result_type result_type; + typedef test_type::param_type param_type; +} diff --git a/libstdc++-v3/testsuite/ext/random/hoyt_distribution/cons/default.cc b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/cons/default.cc new file mode 100644 index 00000000000..39940facc1f --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/cons/default.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::hoyt_distribution<> u; + VERIFY( u.q() == 0.5 ); + VERIFY( u.omega() == 1.0 ); + VERIFY( u.min() == 0.0 ); + typedef __gnu_cxx::hoyt_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits::max() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/hoyt_distribution/cons/parms.cc b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/cons/parms.cc new file mode 100644 index 00000000000..22c8b66dfa9 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/cons/parms.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::hoyt_distribution<> u(0.05, 3.0); + VERIFY( u.q() == 0.05 ); + VERIFY( u.omega() == 3.0 ); + VERIFY( u.min() == 0.0 ); + typedef __gnu_cxx::hoyt_distribution<>::result_type result_type; + VERIFY( u.max() == std::numeric_limits::max() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/equal.cc b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/equal.cc new file mode 100644 index 00000000000..4496be67562 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/equal.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::hoyt_distribution u(0.05, 3.0), v, w; + + VERIFY( v == w ); + VERIFY( !(u == v) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/inequal.cc b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/inequal.cc new file mode 100644 index 00000000000..914e8d933ae --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/inequal.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_cxx::hoyt_distribution u(0.05, 3.0), v, w; + + VERIFY( u != v ); + VERIFY( !(v != w) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/serialize.cc b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/serialize.cc new file mode 100644 index 00000000000..cdf2e63dc48 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/operators/serialize.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringstream str; + __gnu_cxx::hoyt_distribution u(0.05, 3.0), v; + std::minstd_rand0 rng; + + u(rng); // advance + str << u; + + str >> v; + VERIFY( u == v ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/random/hoyt_distribution/requirements/explicit_instantiation/1.cc b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/requirements/explicit_instantiation/1.cc new file mode 100644 index 00000000000..abdc59943eb --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/requirements/explicit_instantiation/1.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include + +template class __gnu_cxx::hoyt_distribution; +template class __gnu_cxx::hoyt_distribution; +template class __gnu_cxx::hoyt_distribution; diff --git a/libstdc++-v3/testsuite/ext/random/hoyt_distribution/requirements/typedefs.cc b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/requirements/typedefs.cc new file mode 100644 index 00000000000..846b1f31552 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/random/hoyt_distribution/requirements/typedefs.cc @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=c++11" } +// { dg-require-cstdint "" } +// +// 2012-10-12 Edward M. Smith-Rowland <3dw4rd@verizon.net> +// +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// . + +#include + +void +test01() +{ + typedef __gnu_cxx::hoyt_distribution test_type; + + typedef test_type::result_type result_type; + typedef test_type::param_type param_type; +}