Skip to content

Commit 9ef3540

Browse files
committed
Replaced ldexp with frexp to eliminate errno being set on some compliers (e.g. clang) on underflow or overflow
1 parent f0a1c2e commit 9ef3540

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

include/boost/math/special_functions/detail/t_distribution_inv.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,10 @@ BOOST_MATH_GPU_ENABLED T inverse_students_t(T df, T u, T v, const Policy& pol, b
404404
// where we use Shaw's tail series.
405405
// The crossover point is roughly exponential in -df:
406406
//
407-
T crossover = ldexp(1.0f, iround(T(df / -0.654f), typename policies::normalise<Policy, policies::rounding_error<policies::ignore_error> >::type()));
408-
if(u > crossover)
407+
int u_exp;
408+
T m_exp = frexp(u, &u_exp);
409+
// The following is equivalent to: u > 2^df/-0.654
410+
if(m_exp > 0 && u_exp < df / 0.654f)
409411
{
410412
result = boost::math::detail::inverse_students_t_hill(df, u, pol);
411413
}

test/test_students_t.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,21 @@ void test_spots(RealType)
258258
static_cast<RealType>(0.1)), // probability.
259259
static_cast<RealType>(-1.475884049), // t
260260
tolerance);
261+
errno = 0;
262+
BOOST_CHECK_CLOSE( // Tests of df high and p low.
263+
::boost::math::cdf(
264+
students_t_distribution<RealType>(1000.), // degrees_of_freedom
265+
static_cast<RealType>(-3.30028272)), // t
266+
static_cast<RealType>(0.0005), // probability.
267+
tolerance);
268+
BOOST_CHECK_EQUAL(errno, 0);
269+
BOOST_CHECK_CLOSE(
270+
::boost::math::quantile(
271+
students_t_distribution<RealType>(1000.), // degrees_of_freedom.
272+
static_cast<RealType>(0.0005)), // probability.
273+
static_cast<RealType>(-3.30028272), // t.
274+
tolerance);
275+
BOOST_CHECK_EQUAL(errno, 0);
261276

262277
BOOST_CHECK_CLOSE(
263278
::boost::math::cdf(

0 commit comments

Comments
 (0)