random.h (negative_binomial_distribution<>:: negative_binomial_distribution(_IntType...
[gcc.git] / libstdc++-v3 / include / bits / random.tcc
index bfc43887b02cdc42aef648d27fa25b49fbe6f291..01ee5824cd9f7df64c564e0910d285f749c53f73 100644 (file)
@@ -1,6 +1,6 @@
 // random number generation (out of line) -*- C++ -*-
 
-// Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2009, 2010, 2011 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
@@ -24,7 +24,7 @@
 
 /** @file bits/random.tcc
  *  This is an internal header file, included by other library headers.
- *  You should not attempt to use it directly.
+ *  Do not attempt to use it directly. @headername{random}
  */
 
 #ifndef _RANDOM_TCC
 
 #include <numeric> // std::accumulate and std::partial_sum
 
-namespace std
+namespace std _GLIBCXX_VISIBILITY(default)
 {
   /*
    * (Further) implementation-space details.
    */
   namespace __detail
   {
+  _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
     // General case for x = (ax + c) mod m -- use Schrage's algorithm to
     // avoid integer overflow.
     //
@@ -100,8 +102,11 @@ namespace std
          *__result = __unary_op(*__first);
        return __result;
       }
+
+  _GLIBCXX_END_NAMESPACE_VERSION
   } // namespace __detail
 
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
     constexpr _UIntType
@@ -1020,7 +1025,7 @@ namespace std
 
        double __cand;
        do
-         __cand = std::ceil(std::log(__aurng()) / __param._M_log_p);
+         __cand = std::floor(std::log(__aurng()) / __param._M_log_1_p);
        while (__cand >= __thr);
 
        return result_type(__cand + __naf);
@@ -1070,7 +1075,7 @@ namespace std
       return __is;
     }
 
-
+  // 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
@@ -1095,7 +1100,7 @@ namespace std
          param_type;
        
        const double __y =
-         _M_gd(__urng, param_type(__p.k(), __p.p() / (1.0 - __p.p())));
+         _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
 
        std::poisson_distribution<result_type> __poisson(__y);
        return __poisson(__urng);
@@ -1429,7 +1434,7 @@ namespace std
       {
        result_type __ret;
        const _IntType __t = __param.t();
-       const _IntType __p = __param.p();
+       const double __p = __param.p();
        const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
        __detail::_Adaptor<_UniformRandomNumberGenerator, double>
          __aurng(__urng);
@@ -2818,6 +2823,8 @@ namespace std
        }
       return __sum / __tmp;
     }
-}
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
 
 #endif