diff --git a/include/boost/math/distributions/non_central_f.hpp b/include/boost/math/distributions/non_central_f.hpp index a6df68b8f..0fd33e6da 100644 --- a/include/boost/math/distributions/non_central_f.hpp +++ b/include/boost/math/distributions/non_central_f.hpp @@ -63,7 +63,7 @@ namespace boost // order p * eps (note not q * eps, since q is calculated as 1-p). // Also note that p_q_precision is passed down from our caller as the // epsilon of the original called values, and not after possible promotion. - if (f(tools::min_value()) <= 3 * p_q_precision * p){ + if (f(tools::min_value()) <= 20 * p_q_precision * p){ return 0; } diff --git a/test/test_nc_f.cpp b/test/test_nc_f.cpp index 4d96f9c22..5a1cd4da6 100644 --- a/test/test_nc_f.cpp +++ b/test/test_nc_f.cpp @@ -344,6 +344,31 @@ void test_spots(RealType, const char* name = nullptr) // Case when Q=1 or Q=0 BOOST_MATH_CHECK_THROW(dist.find_non_centrality(boost::math::complement(x, a, b, 1)), std::domain_error); BOOST_MATH_CHECK_THROW(dist.find_non_centrality(boost::math::complement(x, a, b, 0)), std::domain_error); + // + // Test non centrality finder over a grid of values: + // + RealType values[] = { 1.25, 3.5, 6.75, 8.25 }; + for (RealType v1 : values) + { + for (RealType v2 : values) + { + for (RealType nc : values) + { + for (RealType x : values) + { + boost::math::non_central_f_distribution ref(v1, v2, nc); + RealType P = cdf(ref, x); + RealType Q = cdf(complement(ref, x)); + + RealType nc1 = ref.find_non_centrality(x, v1, v2, P); + RealType nc2 = ref.find_non_centrality(boost::math::complement(x, v1, v2, Q)); + + BOOST_CHECK_CLOSE(nc1, nc, 2 * tolerance); + BOOST_CHECK_CLOSE(nc2, nc, tolerance); + } + } + } + } } // template void test_spots(RealType) BOOST_AUTO_TEST_CASE( test_main )