From c3656f941c8e962d364be082f77798e68d3e9cff Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Mon, 10 Aug 2026 13:14:52 +0100 Subject: [PATCH] Correct ibeta when it's an arcsine distribution. So we don't take the asin of values very close to 1. Fixes: https://github.com/boostorg/math/issues/1429. --- include/boost/math/special_functions/beta.hpp | 10 +++++++++- test/test_students_t.cpp | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/boost/math/special_functions/beta.hpp b/include/boost/math/special_functions/beta.hpp index dc1519c76d..d136fd8ad3 100644 --- a/include/boost/math/special_functions/beta.hpp +++ b/include/boost/math/special_functions/beta.hpp @@ -1285,7 +1285,15 @@ BOOST_MATH_GPU_ENABLED T ibeta_imp(T a, T b, T x, const Policy& pol, bool inv, b { *p_derivative = 1 / (constants::pi() * sqrt(y * x)); } - T p = invert ? asin(sqrt(y)) / constants::half_pi() : asin(sqrt(x)) / constants::half_pi(); + T p; + if (invert) + { + p = (y < 0.75) ? asin(sqrt(y)) / constants::half_pi() : 1 - asin(sqrt(x)) / constants::half_pi(); + } + else + { + p = (x > 0.75) ? 1 - asin(sqrt(y)) / constants::half_pi() : asin(sqrt(x)) / constants::half_pi(); + } if(!normalised) p *= constants::pi(); return p; diff --git a/test/test_students_t.cpp b/test/test_students_t.cpp index 3c63d3d639..dfc0921bb2 100644 --- a/test/test_students_t.cpp +++ b/test/test_students_t.cpp @@ -421,6 +421,7 @@ void test_spots(RealType) { BOOST_CHECK_THROW(boost::math::quantile(students_t_distribution((std::numeric_limits::min)() / 2), static_cast(0.0025f)), std::overflow_error); } + BOOST_CHECK_CLOSE(boost::math::cdf(students_t_distribution(static_cast(1)), ldexp(RealType(1), -30)), static_cast(0.5000000002964491827262478614651948102240210317156775562512071908L), tolerance); } // Student's t pdf tests.