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

Merge pull request #1284 from ak-ambi/develop

Prevent std::ldexp underflowing/overflowing because of hard-coded flo…
This commit is contained in:
Matt Borland
2025-07-07 13:29:47 -04:00
committed by GitHub
2 changed files with 19 additions and 2 deletions

View File

@@ -404,8 +404,10 @@ calculate_real:
// where we use Shaw's tail series.
// The crossover point is roughly exponential in -df:
//
T crossover = ldexp(1.0f, iround(T(df / -0.654f), typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type()));
if(u > crossover)
int u_exp;
T m_exp = frexp(u, &u_exp);
// The following is equivalent to: u > 2^df/-0.654
if(m_exp > 0 && u_exp < df / 0.654f)
{
result = boost::math::detail::inverse_students_t_hill(df, u, pol);
}

View File

@@ -258,6 +258,21 @@ void test_spots(RealType)
static_cast<RealType>(0.1)), // probability.
static_cast<RealType>(-1.475884049), // t
tolerance);
errno = 0;
BOOST_CHECK_CLOSE( // Tests of df high and p low.
::boost::math::cdf(
students_t_distribution<RealType>(1000.), // degrees_of_freedom
static_cast<RealType>(-3.30028272)), // t
static_cast<RealType>(0.0005), // probability.
tolerance);
BOOST_CHECK_EQUAL(errno, 0);
BOOST_CHECK_CLOSE(
::boost::math::quantile(
students_t_distribution<RealType>(1000.), // degrees_of_freedom.
static_cast<RealType>(0.0005)), // probability.
static_cast<RealType>(-3.30028272), // t.
tolerance);
BOOST_CHECK_EQUAL(errno, 0);
BOOST_CHECK_CLOSE(
::boost::math::cdf(