Commit 50060222 by Edward Smith-Rowland

dd the Hoyt and the arcsine distributions as extensions.

From-SVN: r192403
parent e74a506f
...@@ -1015,6 +1015,178 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1015,6 +1015,178 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __is; return __is;
} }
template<typename _RealType>
template<typename _OutputIterator,
typename _UniformRandomNumberGenerator>
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<typename _RealType, typename _CharT, typename _Traits>
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<typename _RealType, typename _CharT, typename _Traits>
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<typename _RealType>
template<typename _UniformRandomNumberGenerator>
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<typename _RealType>
template<typename _UniformRandomNumberGenerator>
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<result_type>::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<typename _RealType>
template<typename _OutputIterator,
typename _UniformRandomNumberGenerator>
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<result_type>::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<typename _RealType, typename _CharT, typename _Traits>
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<typename _RealType, typename _CharT, typename _Traits>
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 _GLIBCXX_END_NAMESPACE_VERSION
} // namespace } // namespace
......
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
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;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
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;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::arcsine_distribution<double> u(-2.0, 3.0), v, w;
VERIFY( v == w );
VERIFY( !(u == v) );
}
int
main()
{
test01();
return 0;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::arcsine_distribution<double> u(-2.0, 3.0), v, w;
VERIFY( u != v );
VERIFY( !(v != w) );
}
int
main()
{
test01();
return 0;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <sstream>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::stringstream str;
__gnu_cxx::arcsine_distribution<double> 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;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
template class __gnu_cxx::arcsine_distribution<float>;
template class __gnu_cxx::arcsine_distribution<double>;
template class __gnu_cxx::arcsine_distribution<long double>;
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
void
test01()
{
typedef __gnu_cxx::arcsine_distribution<double> test_type;
typedef test_type::result_type result_type;
typedef test_type::param_type param_type;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
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<result_type>::max() );
}
int
main()
{
test01();
return 0;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
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<result_type>::max() );
}
int
main()
{
test01();
return 0;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::hoyt_distribution<double> u(0.05, 3.0), v, w;
VERIFY( v == w );
VERIFY( !(u == v) );
}
int
main()
{
test01();
return 0;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::hoyt_distribution<double> u(0.05, 3.0), v, w;
VERIFY( u != v );
VERIFY( !(v != w) );
}
int
main()
{
test01();
return 0;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <sstream>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
std::stringstream str;
__gnu_cxx::hoyt_distribution<double> 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;
}
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
template class __gnu_cxx::hoyt_distribution<float>;
template class __gnu_cxx::hoyt_distribution<double>;
template class __gnu_cxx::hoyt_distribution<long double>;
// { 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
// <http://www.gnu.org/licenses/>.
#include <ext/random>
void
test01()
{
typedef __gnu_cxx::hoyt_distribution<double> test_type;
typedef test_type::result_type result_type;
typedef test_type::param_type param_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