Skip to content

Commit

Permalink
Catch evaluation_error's in temme_method_2_ibeta_inverse (#1175)
Browse files Browse the repository at this point in the history
Catch evaluation_error's in temme_method_2_ibeta_inverse
fixes #1169.
Add test case.
  • Loading branch information
jzmaddock authored Sep 7, 2024
1 parent 1e9b2cc commit cb06899
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
21 changes: 18 additions & 3 deletions include/boost/math/special_functions/detail/ibeta_inverse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,23 @@ BOOST_MATH_GPU_ENABLED T temme_method_2_ibeta_inverse(T /*a*/, T /*b*/, T z, T r
//
// And iterate:
//
x = tools::newton_raphson_iterate(
temme_root_finder<T>(-lu, alpha), x, lower, upper, policies::digits<T, Policy>() / 2);

#ifndef BOOST_MATH_NO_EXCEPTIONS
try {
#endif
x = tools::newton_raphson_iterate(
temme_root_finder<T>(-lu, alpha), x, lower, upper, policies::digits<T, Policy>() / 2);
#ifndef BOOST_MATH_NO_EXCEPTIONS
}
catch (const boost::math::evaluation_error&)
{
// Due to numerical instability we may have cases where no root is found when
// in fact we should just touch the origin. We simply ignore the error here
// and return our best guess for x so far...
// Maybe we should special case the symmetrical parameter case, but it's not clear
// whether that is the only situation when problems can occur.
// See https://github.com/boostorg/math/issues/1169
}
#endif
return x;
}
//
Expand All @@ -321,6 +335,7 @@ BOOST_MATH_GPU_ENABLED T temme_method_3_ibeta_inverse(T a, T b, T p, T q, const
{
BOOST_MATH_STD_USING // ADL of std names


//
// Begin by getting an initial approximation for the quantity
// eta from the dominant part of the incomplete beta:
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ test-suite special_fun :
[ run git_issue_184.cpp ]
[ run git_issue_1137.cpp ]
[ run git_issue_1139.cpp ]
[ run git_issue_1175.cpp ]
[ run special_functions_test.cpp /boost/test//boost_unit_test_framework ]
[ run test_airy.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]
[ run test_bessel_j.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]
Expand Down
25 changes: 25 additions & 0 deletions test/git_issue_1175.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// (C) Copyright Matt Borland 2023.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include "math_unit_test.hpp"
#include <iostream>
#include <boost/math/distributions/beta.hpp>

using namespace std;
using boost::math::beta_distribution;

int main(int argc, char* argv[])
{
double a = 5.0;
double b = 5.0;
double p = 0.5;

beta_distribution<> dist(a, b);
double x = quantile(dist, p);

CHECK_ULP_CLOSE(x, 0.5, 2);

return boost::math::test::report_errors();
}

0 comments on commit cb06899

Please sign in to comment.