diff --git a/include/boost/math/special_functions/legendre.hpp b/include/boost/math/special_functions/legendre.hpp index 5e7f0029a..e6c41470f 100644 --- a/include/boost/math/special_functions/legendre.hpp +++ b/include/boost/math/special_functions/legendre.hpp @@ -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( - function, - "The Legendre Polynomial is defined for" - " -1 <= x <= 1, but got x = %1%.", x, pol); + return policies::raise_domain_error(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( - function, - "The Legendre Polynomial is defined for" - " -1 <= x <= 1, but got x = %1%.", x, pol); + return policies::raise_domain_error(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( - "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("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); diff --git a/test/test_legendre.cpp b/test/test_legendre.cpp index 7551fdd60..bc3289257 100644 --- a/test/test_legendre.cpp +++ b/test/test_legendre.cpp @@ -52,7 +52,7 @@ void expected_results() // // Linux: // - if((std::numeric_limits::digits <= 64) + BOOST_MATH_IF_CONSTEXPR((std::numeric_limits::digits <= 64) && (std::numeric_limits::digits != std::numeric_limits::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::digits == 64) + BOOST_MATH_IF_CONSTEXPR(std::numeric_limits::digits == 64) { add_expected_result( ".*", // compiler diff --git a/test/test_legendre.hpp b/test/test_legendre.hpp index 1a85050f8..885dae91e 100644 --- a/test/test_legendre.hpp +++ b/test/test_legendre.hpp @@ -158,7 +158,7 @@ void test_spots(T, const char* t) BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-4, 2, static_cast(0.5L)), static_cast(5.625000000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast(0.5L)), static_cast(-5696.789530152175143607977274672800795328L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast(0.5L)), static_cast(465.1171875000000000000000000000000000000L), tolerance); - if(std::numeric_limits::max_exponent > std::numeric_limits::max_exponent) + BOOST_MATH_IF_CONSTEXPR(std::numeric_limits::max_exponent > std::numeric_limits::max_exponent) { BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast(0.5L)), static_cast(-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(-0.5L)), static_cast(-5.625000000000000000000000000000000000000L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(7, 5, static_cast(-0.5L)), static_cast(-5696.789530152175143607977274672800795328L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(-7, 4, static_cast(-0.5L)), static_cast(465.1171875000000000000000000000000000000L), tolerance); - if(std::numeric_limits::max_exponent > std::numeric_limits::max_exponent) + BOOST_MATH_IF_CONSTEXPR(std::numeric_limits::max_exponent > std::numeric_limits::max_exponent) { BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(40, 30, static_cast(-0.5L)), static_cast(-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(0.5)), static_cast(0.09375L), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(2, -2, static_cast(1)), static_cast(0), tolerance); BOOST_CHECK_CLOSE_FRACTION(::boost::math::legendre_p(2, -2, static_cast(0)), static_cast(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 @@ -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 a, b; + a = boost::math::legendre_p_zeros(0); + b = boost::math::legendre_p_zeros(-1); + BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), b.begin(), b.end()); + a = boost::math::legendre_p_zeros(1); + b = boost::math::legendre_p_zeros(-2); + BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), b.begin(), b.end()); + a = boost::math::legendre_p_zeros(5); + b = boost::math::legendre_p_zeros(-6); + BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), b.begin(), b.end()); } template