mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Coverage: Remove dead code from legendre.hpp and add more test cases.
This commit is contained in:
@@ -40,10 +40,7 @@ T legendre_imp(unsigned l, T x, const Policy& pol, bool second = false)
|
||||
static const char* function = "boost::math::legrendre_p<%1%>(unsigned, %1%)";
|
||||
// Error handling:
|
||||
if((x < -1) || (x > 1))
|
||||
return policies::raise_domain_error<T>(
|
||||
function,
|
||||
"The Legendre Polynomial is defined for"
|
||||
" -1 <= x <= 1, but got x = %1%.", x, pol);
|
||||
return policies::raise_domain_error<T>(function, "The Legendre Polynomial is defined for -1 <= x <= 1, but got x = %1%.", x, pol);
|
||||
|
||||
T p0, p1;
|
||||
if(second)
|
||||
@@ -84,17 +81,11 @@ T legendre_p_prime_imp(unsigned l, T x, const Policy& pol, T* Pn
|
||||
static const char* function = "boost::math::legrendre_p_prime<%1%>(unsigned, %1%)";
|
||||
// Error handling:
|
||||
if ((x < -1) || (x > 1))
|
||||
return policies::raise_domain_error<T>(
|
||||
function,
|
||||
"The Legendre Polynomial is defined for"
|
||||
" -1 <= x <= 1, but got x = %1%.", x, pol);
|
||||
return policies::raise_domain_error<T>(function, "The Legendre Polynomial is defined for -1 <= x <= 1, but got x = %1%.", x, pol);
|
||||
|
||||
if (l == 0)
|
||||
{
|
||||
if (Pn)
|
||||
{
|
||||
*Pn = 1;
|
||||
}
|
||||
BOOST_MATH_ASSERT(Pn == nullptr); // There are no zeros of P_0 so we shoud never call this with l = 0 and Pn non-null.
|
||||
return 0;
|
||||
}
|
||||
T p0 = 1;
|
||||
@@ -310,10 +301,7 @@ T legendre_p_imp(int l, int m, T x, T sin_theta_power, const Policy& pol)
|
||||
BOOST_MATH_STD_USING
|
||||
// Error handling:
|
||||
if((x < -1) || (x > 1))
|
||||
return policies::raise_domain_error<T>(
|
||||
"boost::math::legendre_p<%1%>(int, int, %1%)",
|
||||
"The associated Legendre Polynomial is defined for"
|
||||
" -1 <= x <= 1, but got x = %1%.", x, pol);
|
||||
return policies::raise_domain_error<T>("boost::math::legendre_p<%1%>(int, int, %1%)", "The associated Legendre Polynomial is defined for -1 <= x <= 1, but got x = %1%.", x, pol);
|
||||
// Handle negative arguments first:
|
||||
if(l < 0)
|
||||
return legendre_p_imp(-l-1, m, x, sin_theta_power, pol);
|
||||
|
||||
@@ -52,7 +52,7 @@ void expected_results()
|
||||
//
|
||||
// Linux:
|
||||
//
|
||||
if((std::numeric_limits<long double>::digits <= 64)
|
||||
BOOST_MATH_IF_CONSTEXPR((std::numeric_limits<long double>::digits <= 64)
|
||||
&& (std::numeric_limits<long double>::digits != std::numeric_limits<double>::digits))
|
||||
{
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
@@ -65,7 +65,7 @@ void expected_results()
|
||||
".*", 10, 5); // test function
|
||||
#endif
|
||||
}
|
||||
if(std::numeric_limits<long double>::digits == 64)
|
||||
BOOST_MATH_IF_CONSTEXPR(std::numeric_limits<long double>::digits == 64)
|
||||
{
|
||||
add_expected_result(
|
||||
".*", // compiler
|
||||
|
||||
@@ -158,7 +158,7 @@ void test_spots(T, const char* t)
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(0.5L)), static_cast<T>(5.625000000000000000000000000000000000000L), tolerance);
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance);
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance);
|
||||
if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent)
|
||||
BOOST_MATH_IF_CONSTEXPR(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent)
|
||||
{
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance);
|
||||
}
|
||||
@@ -167,7 +167,7 @@ void test_spots(T, const char* t)
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast<T>(-0.5L)), static_cast<T>(-5.625000000000000000000000000000000000000L), tolerance);
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast<T>(-0.5L)), static_cast<T>(-5696.789530152175143607977274672800795328L), tolerance);
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast<T>(-0.5L)), static_cast<T>(465.1171875000000000000000000000000000000L), tolerance);
|
||||
if(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent)
|
||||
BOOST_MATH_IF_CONSTEXPR(std::numeric_limits<T>::max_exponent > std::numeric_limits<float>::max_exponent)
|
||||
{
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast<T>(-0.5L)), static_cast<T>(-7.855722083232252643913331343916012143461e45L), tolerance);
|
||||
}
|
||||
@@ -199,6 +199,17 @@ void test_spots(T, const char* t)
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(2, -2, static_cast<T>(0.5)), static_cast<T>(0.09375L), tolerance);
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(2, -2, static_cast<T>(1)), static_cast<T>(0), tolerance);
|
||||
BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(2, -2, static_cast<T>(0)), static_cast<T>(0.125), tolerance);
|
||||
//
|
||||
// Coverage:
|
||||
//
|
||||
#ifndef BOOST_MATH_NO_EXCEPTIONS
|
||||
BOOST_CHECK_THROW(boost::math::legendre_p(2, -1.1), std::domain_error);
|
||||
BOOST_CHECK_THROW(boost::math::legendre_p(2, 1.1), std::domain_error);
|
||||
BOOST_CHECK_THROW(boost::math::legendre_p(2, 3, -1.1), std::domain_error);
|
||||
BOOST_CHECK_THROW(boost::math::legendre_p(2, 3, 1.1), std::domain_error);
|
||||
#endif
|
||||
BOOST_CHECK_EQUAL(boost::math::legendre_p(2, 3, 0.5), T(0));
|
||||
BOOST_CHECK_EQUAL(boost::math::legendre_p(2, 6, 0.5), T(0));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -275,6 +286,23 @@ void test_legendre_p_prime()
|
||||
}
|
||||
++n;
|
||||
}
|
||||
//
|
||||
// Coverage:
|
||||
//
|
||||
#ifndef BOOST_MATH_NO_EXCEPTIONS
|
||||
BOOST_CHECK_THROW(boost::math::legendre_p_prime(2, -1.1), std::domain_error);
|
||||
BOOST_CHECK_THROW(boost::math::legendre_p_prime(2, 1.1), std::domain_error);
|
||||
#endif
|
||||
std::vector<T> a, b;
|
||||
a = boost::math::legendre_p_zeros<T>(0);
|
||||
b = boost::math::legendre_p_zeros<T>(-1);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), b.begin(), b.end());
|
||||
a = boost::math::legendre_p_zeros<T>(1);
|
||||
b = boost::math::legendre_p_zeros<T>(-2);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), b.begin(), b.end());
|
||||
a = boost::math::legendre_p_zeros<T>(5);
|
||||
b = boost::math::legendre_p_zeros<T>(-6);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), b.begin(), b.end());
|
||||
}
|
||||
|
||||
template<class Real>
|
||||
|
||||
Reference in New Issue
Block a user