summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/random.tcc
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-25 10:06:33 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-25 10:06:33 +0000
commitb74d57a52001bad39e29f0a4efc41150d53e0bbd (patch)
treec2c00d3744d6db99bffcbbfba5d53c4e3559288b /libstdc++-v3/include/bits/random.tcc
parent5c55078237e2a812e69d6b76ca8ac82e4b2f3819 (diff)
downloadgcc-b74d57a52001bad39e29f0a4efc41150d53e0bbd.tar.gz
2011-03-25 Paolo Carlini <paolo.carlini@oracle.com>
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171443 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/random.tcc')
-rw-r--r--libstdc++-v3/include/bits/random.tcc11
1 files changed, 5 insertions, 6 deletions
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<typename _IntType>
template<typename _UniformRandomNumberGenerator>
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<result_type> __poisson(__y * (1.0 - p())
- / p());
+ std::poisson_distribution<result_type> __poisson(__y);
return __poisson(__urng);
}
@@ -1100,10 +1099,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef typename std::gamma_distribution<result_type>::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<result_type> __poisson(__y * (1.0 - __p.p())
- / __p.p() );
+ std::poisson_distribution<result_type> __poisson(__y);
return __poisson(__urng);
}