From ff2e697a03ccf7afba8e863f789c76715e005e4c Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 25 Mar 2011 10:06:33 +0000 Subject: [PATCH] random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType, double), [...]): Tweak construction of _M_gd. 2011-03-25 Paolo Carlini * include/bits/random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType, double), negative_binomial_distribution<>:: negative_binomial_distribution(const param_type&)): Tweak construction of _M_gd. * include/bits/random.tcc (negative_binomial_distribution<>:: operator()): Adjust. From-SVN: r171443 --- libstdc++-v3/ChangeLog | 10 ++++++++++ libstdc++-v3/include/bits/random.h | 4 ++-- libstdc++-v3/include/bits/random.tcc | 11 +++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9182dc0ae4e..2facd17af70 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2011-03-25 Paolo Carlini + + * include/bits/random.h (negative_binomial_distribution<>:: + negative_binomial_distribution(_IntType, double), + negative_binomial_distribution<>:: + negative_binomial_distribution(const param_type&)): Tweak + construction of _M_gd. + * include/bits/random.tcc (negative_binomial_distribution<>:: + operator()): Adjust. + 2011-03-24 Paolo Carlini * include/bits/random.h (negative_binomial_distribution<>:: diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index 8b09a98c37b..7b7f5966b3c 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -3804,12 +3804,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION explicit negative_binomial_distribution(_IntType __k = 1, double __p = 0.5) - : _M_param(__k, __p), _M_gd(__k, 1.0) + : _M_param(__k, __p), _M_gd(__k, (1.0 - __p) / __p) { } explicit negative_binomial_distribution(const param_type& __p) - : _M_param(__p), _M_gd(__p.k(), 1.0) + : _M_param(__p), _M_gd(__p.k(), (1.0 - __p.p()) / __p.p()) { } /** diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index 0bbc9fd400d..01ee5824cd9 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -1075,7 +1075,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __is; } - // This is Leger's algorithm. + // This is Leger's algorithm, also in Devroye, Ch. X, Example 1.5. template template typename negative_binomial_distribution<_IntType>::result_type @@ -1085,8 +1085,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const double __y = _M_gd(__urng); // XXX Is the constructor too slow? - std::poisson_distribution __poisson(__y * (1.0 - p()) - / p()); + std::poisson_distribution __poisson(__y); return __poisson(__urng); } @@ -1100,10 +1099,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename std::gamma_distribution::param_type param_type; - const double __y = _M_gd(__urng, param_type(__p.k(), 1.0)); + const double __y = + _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p())); - std::poisson_distribution __poisson(__y * (1.0 - __p.p()) - / __p.p() ); + std::poisson_distribution __poisson(__y); return __poisson(__urng); } -- 2.30.2