2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Fix for inverse ibeta with large a,b.

In this case Temme's method may fail as the incomplete gamma can't cope, but as the function changes over from 0 to 1 very rapidly, we can just use the saddle point as a reasonable starting location for iteration.
See https://github.com/scipy/scipy/issues/21725.
This commit is contained in:
jzmaddock
2025-04-16 17:57:20 +01:00
parent a2fbc935b9
commit e19554c55d
2 changed files with 16 additions and 1 deletions

View File

@@ -683,11 +683,17 @@ BOOST_MATH_GPU_ENABLED T ibeta_inv_imp(T a, T b, T p, T q, const Policy& pol, T*
}
else
y = 1;
if(y > 1e-5)
if((y > 1e-5) && (std::max)(a, b) < 1000)
{
x = temme_method_3_ibeta_inverse(a, b, p, q, pol);
y = 1 - x;
}
else
{
// All options have failed, use the saddle point as a starting location:
x = (std::max)(a, b) / (a + b);
y = 1 - x;
}
}
}
}

View File

@@ -320,5 +320,14 @@ void test_spots(T)
BOOST_CHECK((boost::math::isfinite)(boost::math::ibeta_inv(m, m, static_cast<T>(0.125))));
}
#endif
//
// scipy: https://github.com/scipy/scipy/issues/21725
//
BOOST_CHECK_CLOSE(
::boost::math::ibeta_inv(
static_cast<T>(1.0e11L),
static_cast<T>(1.0e13L),
static_cast<T>(0.995L)),
static_cast<T>(0.0099010703473402885173268397418009652L), 1e-10);
}