diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-06-19 17:49:31 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-06-19 17:49:31 +0000 |
commit | 010799ab1f745b1e863d0b0d7457eec5d5b2512e (patch) | |
tree | a1a1417977e2e3064266363209e102fb113fa755 /libstdc++-v3 | |
parent | 985855e91178ec80e2cd83f81a0f100124d765ca (diff) | |
download | gcc-010799ab1f745b1e863d0b0d7457eec5d5b2512e.tar.gz |
2009-06-19 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/random.h (_Adaptor): Simplify for _DInputType always
a floating point type.
(uniform_int_distribution<>::uniform_int_distribution(_IntType,
_IntType)): Fix second default argument.
(uniform_int_distribution<>::_M_call): Remove.
(uniform_int_distribution<>::operator()(_UniformRandomNumberGenerator&,
const param_type&)): Only declare.
* include/bits/random.tcc (uniform_int_distribution<>::_M_call(
_UniformRandomNumberGenerator&, result_type, result_type, true_type):
Remove.
uniform_int_distribution<>::operator()(_UniformRandomNumberGenerator&,
const param_type&): Define here.
(geometric_distribution<>::operator()(_UniformRandomNumberGenerator&,
const param_type&), discrete_distribution<>::operator()
(_UniformRandomNumberGenerator&, const param_type&),
piecewise_constant_distribution<>::operator()
(_UniformRandomNumberGenerator&, const param_type&),
piecewise_linear_distribution<>::operator()
(_UniformRandomNumberGenerator&, const param_type&)): Use double as
the second template argument of _Adaptor.
* testsuite/26_numerics/random/uniform_int_distribution/cons/
default.cc: Adjust.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148720 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 25 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/random.h | 67 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/random.tcc | 24 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc | 5 |
4 files changed, 56 insertions, 65 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ded7f3e25e8..516e783aa4a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,30 @@ 2009-06-19 Paolo Carlini <paolo.carlini@oracle.com> + * include/bits/random.h (_Adaptor): Simplify for _DInputType always + a floating point type. + (uniform_int_distribution<>::uniform_int_distribution(_IntType, + _IntType)): Fix second default argument. + (uniform_int_distribution<>::_M_call): Remove. + (uniform_int_distribution<>::operator()(_UniformRandomNumberGenerator&, + const param_type&)): Only declare. + * include/bits/random.tcc (uniform_int_distribution<>::_M_call( + _UniformRandomNumberGenerator&, result_type, result_type, true_type): + Remove. + uniform_int_distribution<>::operator()(_UniformRandomNumberGenerator&, + const param_type&): Define here. + (geometric_distribution<>::operator()(_UniformRandomNumberGenerator&, + const param_type&), discrete_distribution<>::operator() + (_UniformRandomNumberGenerator&, const param_type&), + piecewise_constant_distribution<>::operator() + (_UniformRandomNumberGenerator&, const param_type&), + piecewise_linear_distribution<>::operator() + (_UniformRandomNumberGenerator&, const param_type&)): Use double as + the second template argument of _Adaptor. + * testsuite/26_numerics/random/uniform_int_distribution/cons/ + default.cc: Adjust. + +2009-06-19 Paolo Carlini <paolo.carlini@oracle.com> + * include/bits/random.tcc (discrete_distribution<>::param_type:: param_type(size_t, double, double, _Func), discrete_distribution<>::operator()(_UniformRandomNumberGenerator&, diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index ec3dd13cbca..099c5fae1a9 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -95,40 +95,23 @@ namespace std _DInputType min() const - { - if (is_integral<_DInputType>::value) - return _M_g.min(); - else - return _DInputType(0); - } + { return _DInputType(0); } _DInputType max() const - { - if (is_integral<_DInputType>::value) - return _M_g.max(); - else - return _DInputType(1); - } + { return _DInputType(1); } /* * Converts a value generated by the adapted random number generator * into a value in the input domain for the dependent random number * distribution. - * - * Because the type traits are compile time constants only the - * appropriate clause of the if statements will actually be emitted - * by the compiler. */ _DInputType operator()() { - if (is_integral<_DInputType>::value) - return _M_g(); - else - return generate_canonical<_DInputType, - numeric_limits<_DInputType>::digits, - _Engine>(_M_g); + return std::generate_canonical<_DInputType, + std::numeric_limits<_DInputType>::digits, + _Engine>(_M_g); } private: @@ -380,7 +363,7 @@ namespace std static_assert(__w >= __l, "mersenne_twister_engine template arguments out of bounds"); static_assert(__w <= - static_cast<size_t>(numeric_limits<_UIntType>::digits), + static_cast<size_t>(std::numeric_limits<_UIntType>::digits), "mersenne_twister_engine template arguments out of bounds"); static_assert(__a <= (__detail::_Shift<_UIntType, __w>::__value - 1), "mersenne_twister_engine template arguments out of bounds"); @@ -558,8 +541,9 @@ namespace std { __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept) static_assert(__s > 0U && __r > __s - && __w > 0U - && __w <= static_cast<size_t>(numeric_limits<_UIntType>::digits), + && __w > 0U + && __w <= static_cast<size_t> + (std::numeric_limits<_UIntType>::digits), "template arguments out of bounds" " in subtract_with_carry_engine"); @@ -922,7 +906,8 @@ namespace std { static_assert(__w > 0U && __w <= - static_cast<size_t>(numeric_limits<_UIntType>::digits), + static_cast<size_t> + (std::numeric_limits<_UIntType>::digits), "template arguments out of bounds " "in independent_bits_engine"); @@ -1507,7 +1492,8 @@ namespace std typedef uniform_int_distribution<_IntType> distribution_type; explicit - param_type(_IntType __a = 0, _IntType __b = 9) + param_type(_IntType __a = 0, + _IntType __b = std::numeric_limits<_IntType>::max()) : _M_a(__a), _M_b(__b) { _GLIBCXX_DEBUG_ASSERT(_M_a <= _M_b); @@ -1531,7 +1517,8 @@ namespace std * @brief Constructs a uniform distribution object. */ explicit - uniform_int_distribution(_IntType __a = 0, _IntType __b = 9) + uniform_int_distribution(_IntType __a = 0, + _IntType __b = std::numeric_limits<_IntType>::max()) : _M_param(__a, __b) { } @@ -1602,29 +1589,7 @@ namespace std template<typename _UniformRandomNumberGenerator> result_type operator()(_UniformRandomNumberGenerator& __urng, - const param_type& __p) - { - typedef typename _UniformRandomNumberGenerator::result_type - _UResult_type; - return _M_call(__urng, __p.a(), __p.b(), - typename is_integral<_UResult_type>::type()); - } - - private: - template<typename _UniformRandomNumberGenerator> - result_type - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, true_type); - - template<typename _UniformRandomNumberGenerator> - result_type - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, false_type) - { - return result_type((__urng() - __urng.min()) - / (__urng.max() - __urng.min()) - * (__max - __min + 1)) + __min; - } + const param_type& __p); param_type _M_param; }; diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index 846b6b05711..87c46186b57 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -644,13 +644,13 @@ namespace std template<typename _UniformRandomNumberGenerator> typename uniform_int_distribution<_IntType>::result_type uniform_int_distribution<_IntType>:: - _M_call(_UniformRandomNumberGenerator& __urng, - result_type __min, result_type __max, true_type) + operator()(_UniformRandomNumberGenerator& __urng, + const param_type& __param) { // XXX Must be fixed to work well for *arbitrary* __urng.max(), - // __urng.min(), __max, __min. Currently works fine only in the - // most common case __urng.max() - __urng.min() >= __max - __min, - // with __urng.max() > __urng.min() >= 0. + // __urng.min(), __param.b(), __param.a(). Currently works fine only + // in the most common case __urng.max() - __urng.min() >= + // __param.b() - __param.a(), with __urng.max() > __urng.min() >= 0. typedef typename __gnu_cxx::__add_unsigned<typename _UniformRandomNumberGenerator::result_type>::__type __urntype; typedef typename __gnu_cxx::__add_unsigned<result_type>::__type @@ -664,14 +664,14 @@ namespace std const __urntype __urnmin = __urng.min(); const __urntype __urnmax = __urng.max(); const __urntype __urnrange = __urnmax - __urnmin; - const __uctype __urange = __max - __min; + const __uctype __urange = __param.b() - __param.a(); const __uctype __udenom = (__urnrange <= __urange ? 1 : __urnrange / (__urange + 1)); do __ret = (__urntype(__urng()) - __urnmin) / __udenom; - while (__ret > __max - __min); + while (__ret > __param.b() - __param.a()); - return __ret + __min; + return __ret + __param.a(); } template<typename _IntType, typename _CharT, typename _Traits> @@ -799,7 +799,7 @@ namespace std // The largest _RealType convertible to _IntType. const double __thr = std::numeric_limits<_IntType>::max() + __naf; - __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __detail::_Adaptor<_UniformRandomNumberGenerator, double> __aurng(__urng); double __cand; @@ -2021,7 +2021,7 @@ namespace std operator()(_UniformRandomNumberGenerator& __urng, const param_type& __param) { - __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __detail::_Adaptor<_UniformRandomNumberGenerator, double> __aurng(__urng); const double __p = __aurng(); @@ -2193,7 +2193,7 @@ namespace std operator()(_UniformRandomNumberGenerator& __urng, const param_type& __param) { - __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __detail::_Adaptor<_UniformRandomNumberGenerator, double> __aurng(__urng); const double __p = __aurng(); @@ -2383,7 +2383,7 @@ namespace std operator()(_UniformRandomNumberGenerator& __urng, const param_type& __param) { - __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> + __detail::_Adaptor<_UniformRandomNumberGenerator, double> __aurng(__urng); const double __p = __aurng(); diff --git a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc index c1bfc04b0e1..0e83565e0de 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/uniform_int_distribution/cons/default.cc @@ -23,6 +23,7 @@ // 26.4.2.4 Concept RandomNumberDistribution [rand.concept.dist] #include <random> +#include <limits> #include <testsuite_hooks.h> void @@ -32,9 +33,9 @@ test01() std::uniform_int_distribution<int> u; VERIFY( u.a() == 0 ); - VERIFY( u.b() == 9 ); + VERIFY( u.b() == std::numeric_limits<int>::max() ); VERIFY( u.min() == 0 ); - VERIFY( u.max() == 9 ); + VERIFY( u.max() == std::numeric_limits<int>::max() ); } int main() |