Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78090 - trunk/boost/math/distributions/detail
From: john_at_[hidden]
Date: 2012-04-20 06:51:56


Author: johnmaddock
Date: 2012-04-20 06:51:55 EDT (Fri, 20 Apr 2012)
New Revision: 78090
URL: http://svn.boost.org/trac/boost/changeset/78090

Log:
Add checks to discrete quantile finder to handle cases where there is no true answer.
Fixes #6805.
Text files modified:
   trunk/boost/math/distributions/detail/inv_discrete_quantile.hpp | 10 ++++++++--
   1 files changed, 8 insertions(+), 2 deletions(-)

Modified: trunk/boost/math/distributions/detail/inv_discrete_quantile.hpp
==============================================================================
--- trunk/boost/math/distributions/detail/inv_discrete_quantile.hpp (original)
+++ trunk/boost/math/distributions/detail/inv_discrete_quantile.hpp 2012-04-20 06:51:55 EDT (Fri, 20 Apr 2012)
@@ -124,6 +124,8 @@
             --count;
             if(fb == 0)
                return b;
+ if(a == b)
+ return b; // can't go any higher!
          }
          else
          {
@@ -135,6 +137,8 @@
             --count;
             if(fa == 0)
                return a;
+ if(a == b)
+ return a; // We can't go any lower than this!
          }
       }
    }
@@ -208,7 +212,7 @@
          // Zero is to the right of x2, so walk upwards
          // until we find it:
          //
- while((boost::math::sign)(fb) == (boost::math::sign)(fa))
+ while(((boost::math::sign)(fb) == (boost::math::sign)(fa)) && (a != b))
          {
             if(count == 0)
                policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", b, policy_type());
@@ -228,7 +232,7 @@
          // Zero is to the left of a, so walk downwards
          // until we find it:
          //
- while((boost::math::sign)(fb) == (boost::math::sign)(fa))
+ while(((boost::math::sign)(fb) == (boost::math::sign)(fa)) && (a != b))
          {
             if(fabs(a) < tools::min_value<value_type>())
             {
@@ -255,6 +259,8 @@
       return a;
    if(fb == 0)
       return b;
+ if(a == b)
+ return b; // Ran out of bounds trying to bracket - there is no answer!
    //
    // Adjust bounds so that if we're looking for an integer
    // result, then both ends round the same way:


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