summaryrefslogtreecommitdiff
path: root/boost/math/distributions/detail/inv_discrete_quantile.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/math/distributions/detail/inv_discrete_quantile.hpp')
-rw-r--r--boost/math/distributions/detail/inv_discrete_quantile.hpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/boost/math/distributions/detail/inv_discrete_quantile.hpp b/boost/math/distributions/detail/inv_discrete_quantile.hpp
index 4d28e52936..9397e7c7c2 100644
--- a/boost/math/distributions/detail/inv_discrete_quantile.hpp
+++ b/boost/math/distributions/detail/inv_discrete_quantile.hpp
@@ -124,6 +124,8 @@ typename Dist::value_type
--count;
if(fb == 0)
return b;
+ if(a == b)
+ return b; // can't go any higher!
}
else
{
@@ -135,6 +137,8 @@ typename Dist::value_type
--count;
if(fa == 0)
return a;
+ if(a == b)
+ return a; // We can't go any lower than this!
}
}
}
@@ -208,7 +212,7 @@ typename Dist::value_type
// 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 @@ typename Dist::value_type
// 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 @@ typename Dist::value_type
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: