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

Begin improving ibeta coverage.

This commit is contained in:
jzmaddock
2024-01-22 19:28:16 +00:00
parent 1bf4096273
commit 27b3f9ea09
6 changed files with 29 additions and 16 deletions

View File

@@ -28,10 +28,8 @@ inline T cyl_bessel_j_prime_imp(T v, T x, const Policy& pol)
//
// Prevent complex result:
//
if (x < 0 && floor(v) != v)
return boost::math::policies::raise_domain_error<T>(
function,
"Got x = %1%, but function requires x >= 0", x, pol);
if ((x < 0) && (floor(v) != v))
return boost::math::policies::raise_domain_error<T>(function, "Got x = %1%, but function requires x >= 0", x, pol);
//
// Special cases for x == 0:
//
@@ -43,9 +41,8 @@ inline T cyl_bessel_j_prime_imp(T v, T x, const Policy& pol)
return static_cast<T>(-0.5);
else if (floor(v) == v || v > 1)
return 0;
else return boost::math::policies::raise_domain_error<T>(
function,
"Got x = %1%, but function is indeterminate for this order", x, pol);
else
return boost::math::policies::raise_domain_error<T>(function, "Got x = %1%, but function is indeterminate for this order", x, pol);
}
//
// Special case for large x: use asymptotic expansion:

View File

@@ -331,7 +331,7 @@ T ibeta_power_terms(T a,
{
l += log(result);
if(l >= tools::log_max_value<T>())
return policies::raise_overflow_error<T>(function, nullptr, pol);
return policies::raise_overflow_error<T>(function, nullptr, pol); // LCOV_EXCL_LINE we can probably never get here, probably!
result = exp(l);
}
else
@@ -347,7 +347,7 @@ T ibeta_power_terms(T a,
{
l += log(result);
if(l >= tools::log_max_value<T>())
return policies::raise_overflow_error<T>(function, nullptr, pol);
return policies::raise_overflow_error<T>(function, nullptr, pol); // LCOV_EXCL_LINE we can probably never get here, probably!
result = exp(l);
}
else
@@ -386,7 +386,7 @@ T ibeta_power_terms(T a,
{
l2 += l1 + log(result);
if(l2 >= tools::log_max_value<T>())
return policies::raise_overflow_error<T>(function, nullptr, pol);
return policies::raise_overflow_error<T>(function, nullptr, pol); // LCOV_EXCL_LINE we can probably never get here, probably!
result = exp(l2);
}
}
@@ -404,7 +404,7 @@ T ibeta_power_terms(T a,
{
l2 += l1 + log(result);
if(l2 >= tools::log_max_value<T>())
return policies::raise_overflow_error<T>(function, nullptr, pol);
return policies::raise_overflow_error<T>(function, nullptr, pol); // LCOV_EXCL_LINE we can probably never get here, probably!
result = exp(l2);
}
}
@@ -423,9 +423,9 @@ T ibeta_power_terms(T a,
if (0 == result)
{
if ((a > 1) && (x == 0))
return result; // true zero
return result; // true zero LCOV_EXCL_LINE we can probably never get here
if ((b > 1) && (y == 0))
return result; // true zero
return result; // true zero LCOV_EXCL_LINE we can probably never get here
return boost::math::policies::raise_underflow_error<T>(function, nullptr, pol);
}
@@ -666,7 +666,7 @@ T ibeta_series(T a, T b, T x, T s0, const Lanczos&, bool normalised, T* p_deriva
result = Lanczos::lanczos_sum_expG_scaled(c) / (Lanczos::lanczos_sum_expG_scaled(a) * Lanczos::lanczos_sum_expG_scaled(b));
if (!(boost::math::isfinite)(result))
result = 0;
result = 0; // LCOV_EXCL_LINE we can probably never get here, covered already above?
T l1 = log(cgh / bgh) * (b - 0.5f);
T l2 = log(x * cgh / agh) * a;

View File

@@ -275,7 +275,7 @@ void test_bessel(T, const char* name)
// special cases for code coverage:
//
T tolerance = boost::math::tools::epsilon<T>() * 2000;
BOOST_CHECK_CLOSE_FRACTION(boost::math::sph_bessel(200, T(0.5)), T(3.070403008048099934928128420285169174541102108657574230431e-497L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(boost::math::sph_bessel(200, T(0.5)), SC_(3.070403008048099934928128420285169174541102108657574230431e-497), tolerance);
BOOST_MATH_CHECK_THROW(boost::math::sph_bessel(2, T(-2.0)), std::domain_error);
}

View File

@@ -221,7 +221,7 @@ void test_bessel(T, const char* name)
if (std::numeric_limits<T>::has_infinity)
{
BOOST_CHECK_EQUAL(boost::math::cyl_neumann(T(0), T(0)), -std::numeric_limits<T>::infinity());
BOOST_CHECK_EQUAL(boost::math::sph_neumann(2, (std::numeric_limits<T>::min)() * 1.5f), -std::numeric_limits<T>::infinity());
BOOST_CHECK_EQUAL(boost::math::sph_neumann(2, boost::math::tools::min_value<T>() * 1.5f), -std::numeric_limits<T>::infinity());
T small = 5.69289e-1645L;
if (small != 0)
{

View File

@@ -97,11 +97,17 @@ void test_spots(T)
BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), static_cast<T>(1)), static_cast<T>(0.25), tolerance);
BOOST_CHECK_CLOSE(::boost::math::beta(small, static_cast<T>(4)), 1/small, tolerance);
BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), small), 1/small, tolerance);
BOOST_CHECK_CLOSE(::boost::math::beta(small, static_cast<T>(4)), 1/small, tolerance);
BOOST_CHECK_CLOSE(::boost::math::beta(small, small / 2), boost::math::tgamma(small) * boost::math::tgamma(small / 2) / boost::math::tgamma(small + small / 2), tolerance);
BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(4), static_cast<T>(20)), static_cast<T>(0.00002823263692828910220214568040654997176736L), tolerance);
if ((std::numeric_limits<T>::digits < 100) && (std::numeric_limits<T>::digits != 0))
{
// Inexact input, so disable for ultra precise long doubles:
BOOST_CHECK_CLOSE(::boost::math::beta(static_cast<T>(0.0125L), static_cast<T>(0.000023L)), static_cast<T>(43558.24045647538375006349016083320744662L), tolerance * 2);
}
BOOST_CHECK_THROW(boost::math::beta(static_cast<T>(0), static_cast<T>(1)), std::domain_error);
BOOST_CHECK_THROW(boost::math::beta(static_cast<T>(-1), static_cast<T>(1)), std::domain_error);
BOOST_CHECK_THROW(boost::math::beta(static_cast<T>(1), static_cast<T>(-1)), std::domain_error);
BOOST_CHECK_THROW(boost::math::beta(static_cast<T>(1), static_cast<T>(0)), std::domain_error);
}

View File

@@ -458,5 +458,15 @@ void test_spots(T)
static_cast<T>(4.5),
ldexp(static_cast<T>(1), -557)),
static_cast<T>(5.24647512910420109893867082626308082567071751558842352760e-167L), tolerance * 20);
T tiny = boost::math::tools::min_value<T>() / 2;
T small = boost::math::tools::epsilon<T>();
if (tiny != 0)
{
BOOST_CHECK_EQUAL(boost::math::ibeta(tiny, small, small), 1);
}
BOOST_CHECK_EQUAL(boost::math::ibeta(static_cast<T>(2), static_cast<T>(1), static_cast<T>(0)), 0);
BOOST_CHECK_EQUAL(boost::math::ibeta(static_cast<T>(1), static_cast<T>(2), static_cast<T>(0)), 0);
}