2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-28 07:22:12 +00:00

Add checks to discrete quantile finder to handle cases where there is no true answer.

Fixes #6805.

[SVN r78090]
This commit is contained in:
John Maddock
2012-04-20 10:51:55 +00:00
parent b543f138b6
commit 15baa10fac

View File

@@ -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: