Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
only solve problems if have enough precision
  • Loading branch information
ryanelandt committed Jul 25, 2023
commit 0909d7cc9c3d06bcc6dadebe598bbfecbe4d16ab
19 changes: 8 additions & 11 deletions include/boost/math/special_functions/detail/ibeta_inverse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,16 @@ namespace boost{ namespace math{ namespace detail{
template <class T>
struct temme_root_finder
{
temme_root_finder(const T t_, const T a_) : t(t_), a(a_) {}
temme_root_finder(const T t_, const T a_) : t(t_), a(a_) {
const T x_extrema = 1 / (1 + a);
BOOST_MATH_ASSERT(0 < x_extrema && x_extrema < 1);
}

boost::math::tuple<T, T> operator()(T x)
{
BOOST_MATH_STD_USING // ADL of std names

T y = 1 - x;
if(y == 0)
{
T big = tools::max_value<T>() / 4;
return boost::math::make_tuple(static_cast<T>(-big), static_cast<T>(-big));
}
if(x == 0)
{
T big = tools::max_value<T>() / 4;
return boost::math::make_tuple(static_cast<T>(-big), big);
}
T f = log(x) + a * log(y) + t;
T f1 = (1 / x) - (a / (y));
return boost::math::make_tuple(f, f1);
Expand Down Expand Up @@ -410,6 +403,10 @@ T temme_method_3_ibeta_inverse(T a, T b, T p, T q, const Policy& pol)
T lower = eta < mu ? cross : 0;
T upper = eta < mu ? 1 : cross;
T x = (lower + upper) / 2;

// Early exit for cases with numerical precision issues.
if (cross == 0 || cross == 1) { return cross; }

x = tools::newton_raphson_iterate(
temme_root_finder<T>(u, mu), x, lower, upper, policies::digits<T, Policy>() / 2);
#ifdef BOOST_INSTRUMENT
Expand Down