summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorAndrey Zholos <aaz@althenia.net>2011-03-14 17:57:48 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2011-03-14 17:57:48 +0000
commitd8d4db3345ec3271a5edf4bd84e999662cd8e2e2 (patch)
tree252af3acb8afb7f38157c3d59aadf4acfdef3cd4 /libstdc++-v3
parent7edc478cef220dd4fa0dbe3a50c1030abac83ec1 (diff)
downloadgcc-d8d4db3345ec3271a5edf4bd84e999662cd8e2e2.tar.gz
re PR libstdc++/48114 ([C++0x] binomial_distribution incorrect for p > .5 and geometric_distribution wrongly implements the TR1 definition)
2011-03-14 Andrey Zholos <aaz@althenia.net> PR libstdc++/48114 * include/bits/random.h (geometric_distribution): Correct formula in comment, per C++0x. (geometric_distribution<>::param_type::param_type(double)): Fix check. (geometric_distribution<>::param_type::_M_initialize): Store log(1 - p). * include/bits/random.tcc (geometric_distribution<>::operator()): Fix computation. (binomial_distribution<>::operator()): Likewise. From-SVN: r170946
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog12
-rw-r--r--libstdc++-v3/include/bits/random.h12
-rw-r--r--libstdc++-v3/include/bits/random.tcc4
3 files changed, 20 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 6c3f1d34cda..ef93431bf09 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,15 @@
+2011-03-14 Andrey Zholos <aaz@althenia.net>
+
+ PR libstdc++/48114
+ * include/bits/random.h (geometric_distribution): Correct formula
+ in comment, per C++0x.
+ (geometric_distribution<>::param_type::param_type(double)): Fix check.
+ (geometric_distribution<>::param_type::_M_initialize):
+ Store log(1 - p).
+ * include/bits/random.tcc (geometric_distribution<>::operator()):
+ Fix computation.
+ (binomial_distribution<>::operator()): Likewise.
+
2011-03-09 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/util/testsuite_rvalref.h: Minor tweaks.
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index 5c406a648c3..26cec8a885e 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -1,6 +1,6 @@
// random number generation -*- 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
@@ -3589,7 +3589,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief A discrete geometric random number distribution.
*
* The formula for the geometric probability density function is
- * @f$p(i|p) = (1 - p)p^{i-1}@f$ where @f$p@f$ is the parameter of the
+ * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the
* distribution.
*/
template<typename _IntType = int>
@@ -3611,8 +3611,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
param_type(double __p = 0.5)
: _M_p(__p)
{
- _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0)
- && (_M_p <= 1.0));
+ _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0)
+ && (_M_p < 1.0));
_M_initialize();
}
@@ -3627,11 +3627,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
private:
void
_M_initialize()
- { _M_log_p = std::log(_M_p); }
+ { _M_log_1_p = std::log(1.0 - _M_p); }
double _M_p;
- double _M_log_p;
+ double _M_log_1_p;
};
// constructors and member function
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index 20f7667e298..4b17e914e56 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -1025,7 +1025,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
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);
@@ -1434,7 +1434,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
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);