|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75168 - in trunk/boost/math: distributions tools
From: john_at_[hidden]
Date: 2011-10-29 13:26:27
Author: johnmaddock
Date: 2011-10-29 13:26:26 EDT (Sat, 29 Oct 2011)
New Revision: 75168
URL: http://svn.boost.org/trac/boost/changeset/75168
Log:
Allow precision.hpp to work with number types in base 10.
Fix binomial_distribution quantile when success_fraction is 1.
Fixes #6069.
Text files modified:
trunk/boost/math/distributions/binomial.hpp | 4 ++++
trunk/boost/math/tools/precision.hpp | 18 +++++++++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
Modified: trunk/boost/math/distributions/binomial.hpp
==============================================================================
--- trunk/boost/math/distributions/binomial.hpp (original)
+++ trunk/boost/math/distributions/binomial.hpp 2011-10-29 13:26:26 EDT (Sat, 29 Oct 2011)
@@ -233,6 +233,10 @@
{ // p <= pdf(dist, 0) == cdf(dist, 0)
return 0; // So the only reasonable result is zero.
} // And root finder would fail otherwise.
+ if(success_fraction == 1)
+ { // our formulae break down in this case:
+ return p > 0.5f ? trials : 0;
+ }
// Solve for quantile numerically:
//
Modified: trunk/boost/math/tools/precision.hpp
==============================================================================
--- trunk/boost/math/tools/precision.hpp (original)
+++ trunk/boost/math/tools/precision.hpp 2011-10-29 13:26:26 EDT (Sat, 29 Oct 2011)
@@ -45,12 +45,14 @@
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized);
- BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2);
+ BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10);
#else
BOOST_ASSERT(::std::numeric_limits<T>::is_specialized);
- BOOST_ASSERT(::std::numeric_limits<T>::radix == 2);
+ BOOST_ASSERT(::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10);
#endif
- return std::numeric_limits<T>::digits;
+ return std::numeric_limits<T>::radix == 2
+ ? std::numeric_limits<T>::digits
+ : ((std::numeric_limits<T>::digits + 1) * 1000L) / 301L;
}
template <class T>
@@ -184,9 +186,10 @@
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
typedef typename mpl::if_c<
- std::numeric_limits<T>::max_exponent == 128
+ (std::numeric_limits<T>::radix == 2) &&
+ (std::numeric_limits<T>::max_exponent == 128
|| std::numeric_limits<T>::max_exponent == 1024
- || std::numeric_limits<T>::max_exponent == 16384,
+ || std::numeric_limits<T>::max_exponent == 16384),
mpl::int_<std::numeric_limits<T>::max_exponent>,
mpl::int_<0>
>::type tag_type;
@@ -205,9 +208,10 @@
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
typedef typename mpl::if_c<
- std::numeric_limits<T>::max_exponent == 128
+ (std::numeric_limits<T>::radix == 2) &&
+ (std::numeric_limits<T>::max_exponent == 128
|| std::numeric_limits<T>::max_exponent == 1024
- || std::numeric_limits<T>::max_exponent == 16384,
+ || std::numeric_limits<T>::max_exponent == 16384),
mpl::int_<std::numeric_limits<T>::max_exponent>,
mpl::int_<0>
>::type tag_type;
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