Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/boost/math/distributions/students_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ BOOST_MATH_GPU_ENABLED RealType calculate_hill_df_guess(
RealType za = quantile(complement(n, alpha));
RealType zb = quantile(complement(n, beta));

RealType v_norm = pow((za + zb) * sd / difference_from_mean, 2) - 1;
RealType v_norm = static_cast<RealType>(pow((za + zb) * sd / difference_from_mean, 2) - 1);
RealType hint = v_norm + (za * za - za * zb + zb * zb + 1) / 2;

return (hint <= 0) ? RealType(1) : hint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,14 @@ BOOST_MATH_GPU_ENABLED T fast_students_t_quantile_imp(T df, T p, const Policy& p
// Get cdf from incomplete beta result:
T p0 = f0 / 2 - p;
// Get pdf from derivative:
T p1 = f1 * sqrt(y * xb * xb * xb / df);
T rxb = sqrt(xb);
T p1 = f1 * sqrt(y / df);
p1 *= rxb;
p1 *= rxb;
p1 *= rxb;
// If p1 has underflowed, all subsequent calculations will fail:
if (p1 < tools::min_value<T>())
return t;
//
// Second derivative divided by p1:
//
Expand Down
18 changes: 18 additions & 0 deletions test/test_students_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,24 @@ void test_spots(RealType)
BOOST_CHECK_THROW(boost::math::quantile(students_t_distribution<RealType>((std::numeric_limits<RealType>::min)() / 2), static_cast<RealType>(0.0025f)), std::overflow_error);
}
BOOST_CHECK_CLOSE(boost::math::cdf(students_t_distribution<RealType>(static_cast<RealType>(1)), ldexp(RealType(1), -30)), static_cast<RealType>(0.5000000002964491827262478614651948102240210317156775562512071908L), tolerance);
// https://github.com/boostorg/math/issues/1436
// We have quite limited precision in this area:
if (boost::math::tools::digits<RealType>() > boost::math::tools::digits<float>())
{
using std::ldexp;
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType>(static_cast<RealType>(3)), ldexp(RealType(1), -800)), static_cast<RealType>(-1.94452005735447553162080266906e+80L), 1e-8);
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType>(static_cast<RealType>(3)), ldexp(RealType(1), -1000)), static_cast<RealType>(-2.27760708321880957407749124767e+100L), 1e-8);
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType>(static_cast<RealType>(5)), ldexp(RealType(1), -1000)), static_cast<RealType>(-2.52030967154944272146770707689e+60L), 1e-8);
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType>(static_cast<RealType>(7)), ldexp(RealType(1), -1000)), static_cast<RealType>(-2.02884419021075115948274137329e+43L), 1e-8);
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType>(static_cast<RealType>(10)), ldexp(RealType(1), -1000)), static_cast<RealType>(-3.25092256692541451558538754799e+30L), 1e-8);
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType>(static_cast<RealType>(30)), ldexp(RealType(1), -1000)), static_cast<RealType>(-54306462721.8246714347211540407L), 1e-8);
using nopromote = boost::math::policies::policy<boost::math::policies::promote_double<false>>;
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType, nopromote>(static_cast<RealType>(30)), ldexp(RealType(1), -1000)), static_cast<RealType>(-54306462721.8246714347211540407L), 1e-8);
if (boost::math::tools::digits<RealType>() > boost::math::tools::digits<double>())
{
BOOST_CHECK_CLOSE_FRACTION(boost::math::quantile(students_t_distribution<RealType>(static_cast<RealType>(30)), ldexp(RealType(1), -16000)), static_cast<RealType>(-1.77766265021682828433490865393e+161L), 1e-8);
}
}
}

// Student's t pdf tests.
Expand Down
Loading