|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63092 - trunk/boost/random
From: steven_at_[hidden]
Date: 2010-06-19 00:31:33
Author: steven_watanabe
Date: 2010-06-19 00:31:28 EDT (Sat, 19 Jun 2010)
New Revision: 63092
URL: http://svn.boost.org/trac/boost/changeset/63092
Log:
Fix my floor silliness. e.g. int(-0.5) != floor(-0.5)
Text files modified:
trunk/boost/random/binomial_distribution.hpp | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)
Modified: trunk/boost/random/binomial_distribution.hpp
==============================================================================
--- trunk/boost/random/binomial_distribution.hpp (original)
+++ trunk/boost/random/binomial_distribution.hpp 2010-06-19 00:31:28 EDT (Sat, 19 Jun 2010)
@@ -244,10 +244,8 @@
bool use_inversion() const
{
- // According to the paper, 11 should be safe,
- // but I was having undiagnosed accuracy problems.
- // A value of 20 should be safe
- return m < 20;
+ // BTRD is safe when np >= 10
+ return m < 11;
}
// computes the correction factor for the Stirling approximation
@@ -295,8 +293,8 @@
RealType v = uniform_01<RealType>()(urng);
if(v <= btrd.u_rv_r) {
RealType u = v/btrd.v_r - 0.43;
- return static_cast<IntType>(
- (2*btrd.a/(0.5 - abs(u)) + btrd.b)*u + btrd.c);
+ return static_cast<IntType>(floor(
+ (2*btrd.a/(0.5 - abs(u)) + btrd.b)*u + btrd.c));
}
if(v >= btrd.v_r) {
@@ -308,7 +306,7 @@
}
RealType us = 0.5 - abs(u);
- IntType k = static_cast<IntType>((2*btrd.a/us + btrd.b)*u + btrd.c);
+ IntType k = static_cast<IntType>(floor((2*btrd.a/us + btrd.b)*u + btrd.c));
if(k < 0 || k > _t) continue;
v = v*btrd.alpha/(btrd.a/(us*us) + btrd.b);
IntType km = abs(k - m);
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk