random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType...
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 25 Mar 2011 10:06:33 +0000 (10:06 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 25 Mar 2011 10:06:33 +0000 (10:06 +0000)
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.

From-SVN: r171443

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/random.h
libstdc++-v3/include/bits/random.tcc

index 9182dc0ae4e6e0fc45c05f1c1f31b2d43ff9332c..2facd17af70c22818963b42a09791c17d54ef642 100644 (file)
@@ -1,3 +1,13 @@
+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.
+
 2011-03-24  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * include/bits/random.h (negative_binomial_distribution<>::
index 8b09a98c37bc89c17ccc949b56b8882db4feed6f..7b7f5966b3c79d9cb9e867a4faa3f1ad147f9654 100644 (file)
@@ -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())
       { }
 
       /**
index 0bbc9fd400d45798f49b642185b322341a6b9cb1..01ee5824cd9f7df64c564e0910d285f749c53f73 100644 (file)
@@ -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);
       }