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

Coverage: Cosmetic changes to log1p plus more tests.

Also hook test_log1p_simple.cpp up to Jamfile.v2 as it had been omitted for some reason.
This commit is contained in:
jzmaddock
2025-05-04 16:12:13 +01:00
parent 6280934567
commit 7556310aae
4 changed files with 28 additions and 29 deletions

View File

@@ -96,11 +96,9 @@ BOOST_MATH_GPU_ENABLED T log1p_imp(T const & x, const Policy& pol, const boost::
constexpr auto function = "boost::math::log1p<%1%>(%1%)";
if((x < -1) || (boost::math::isnan)(x))
return policies::raise_domain_error<T>(
function, "log1p(x) requires x > -1, but got x = %1%.", x, pol);
return policies::raise_domain_error<T>(function, "log1p(x) requires x > -1, but got x = %1%.", x, pol);
if(x == -1)
return -policies::raise_overflow_error<T>(
function, nullptr, pol);
return -policies::raise_overflow_error<T>(function, nullptr, pol);
result_type a = abs(result_type(x));
if(a > result_type(0.5f))
@@ -126,11 +124,9 @@ BOOST_MATH_GPU_ENABLED T log1p_imp(T const& x, const Policy& pol, const boost::m
constexpr auto function = "boost::math::log1p<%1%>(%1%)";
if(x < -1)
return policies::raise_domain_error<T>(
function, "log1p(x) requires x > -1, but got x = %1%.", x, pol);
return policies::raise_domain_error<T>(function, "log1p(x) requires x > -1, but got x = %1%.", x, pol);
if(x == -1)
return -policies::raise_overflow_error<T>(
function, nullptr, pol);
return -policies::raise_overflow_error<T>(function, nullptr, pol);
T a = fabs(x);
if(a > 0.5f)
@@ -179,11 +175,9 @@ BOOST_MATH_GPU_ENABLED T log1p_imp(T const& x, const Policy& pol, const boost::m
constexpr auto function = "boost::math::log1p<%1%>(%1%)";
if(x < -1)
return policies::raise_domain_error<T>(
function, "log1p(x) requires x > -1, but got x = %1%.", x, pol);
return policies::raise_domain_error<T>(function, "log1p(x) requires x > -1, but got x = %1%.", x, pol);
if(x == -1)
return -policies::raise_overflow_error<T>(
function, nullptr, pol);
return -policies::raise_overflow_error<T>(function, nullptr, pol);
T a = fabs(x);
if(a > 0.5f)
@@ -301,11 +295,9 @@ template <class Policy>
BOOST_MATH_GPU_ENABLED inline float log1p(float x, const Policy& pol)
{
if(x < -1)
return policies::raise_domain_error<float>(
"log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
return policies::raise_domain_error<float>("log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
if(x == -1)
return -policies::raise_overflow_error<float>(
"log1p<%1%>(%1%)", nullptr, pol);
return -policies::raise_overflow_error<float>("log1p<%1%>(%1%)", nullptr, pol);
return std::log1p(x);
}
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
@@ -313,11 +305,9 @@ template <class Policy>
BOOST_MATH_GPU_ENABLED inline long double log1p(long double x, const Policy& pol)
{
if(x < -1)
return policies::raise_domain_error<long double>(
"log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
return policies::raise_domain_error<long double>("log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
if(x == -1)
return -policies::raise_overflow_error<long double>(
"log1p<%1%>(%1%)", nullptr, pol);
return -policies::raise_overflow_error<long double>("log1p<%1%>(%1%)", nullptr, pol);
return std::log1p(x);
}
#endif
@@ -325,11 +315,9 @@ template <class Policy>
BOOST_MATH_GPU_ENABLED inline double log1p(double x, const Policy& pol)
{
if(x < -1)
return policies::raise_domain_error<double>(
"log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
return policies::raise_domain_error<double>("log1p<%1%>(%1%)", "log1p(x) requires x > -1, but got x = %1%.", x, pol);
if(x == -1)
return -policies::raise_overflow_error<double>(
"log1p<%1%>(%1%)", nullptr, pol);
return -policies::raise_overflow_error<double>("log1p<%1%>(%1%)", nullptr, pol);
return std::log1p(x);
}
@@ -350,11 +338,9 @@ BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type
constexpr auto function = "boost::math::log1pmx<%1%>(%1%)";
if(x < -1)
return policies::raise_domain_error<T>(
function, "log1pmx(x) requires x > -1, but got x = %1%.", x, pol);
return policies::raise_domain_error<T>(function, "log1pmx(x) requires x > -1, but got x = %1%.", x, pol);
if(x == -1)
return -policies::raise_overflow_error<T>(
function, nullptr, pol);
return -policies::raise_overflow_error<T>(function, nullptr, pol);
result_type a = abs(result_type(x));
if(a > result_type(0.95f))

View File

@@ -184,6 +184,7 @@ test-suite special_fun :
[ run log1p_expm1_test.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]
[ run log1p_expm1_extra_test.cpp pch_light /boost/test//boost_unit_test_framework : : : [ check-target-builds ../config//has_float128 "GCC libquadmath and __float128 support" : <linkflags>-lquadmath ] ]
[ run log1p_expm1_stdfloat_test.cpp pch_light /boost/test//boost_unit_test_framework ]
[ run test_log1p_simple.cpp ]
[ run powm1_sqrtp1m1_test.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]
[ run git_issue_705.cpp /boost/test//boost_unit_test_framework ]
[ run git_issue_810.cpp /boost/test//boost_unit_test_framework ]

View File

@@ -79,12 +79,13 @@ void test(T, const char* type_name)
BOOST_CHECK_EQUAL(boost::math::expm1(T(-std::numeric_limits<T>::infinity())), m_one);
BOOST_CHECK_EQUAL(boost::math::expm1(std::numeric_limits<T>::infinity()), std::numeric_limits<T>::infinity());
#ifndef BOOST_BORLANDC
#ifndef BOOST_NO_EXCEPTIONS
#ifndef BOOST_MATH_NO_EXCEPTIONS
// When building with Borland's compiler, simply the *presence*
// of these tests cause other unrelated tests to fail!!! :-(
using namespace boost::math::policies;
typedef policy<overflow_error<throw_on_error> > pol;
BOOST_MATH_CHECK_THROW(boost::math::log1p(m_one, pol()), std::overflow_error);
BOOST_MATH_CHECK_THROW(boost::math::log1p(static_cast<T>(-2), pol()), std::domain_error);
BOOST_MATH_CHECK_THROW(boost::math::expm1(std::numeric_limits<T>::infinity(), pol()), std::overflow_error);
#endif
#endif

View File

@@ -34,6 +34,17 @@ void test_log1pmx()
const T value (dist(rng));
CHECK_ULP_CLOSE(std::log1p(value) - value, boost::math::log1pmx(value), 1e9);
}
std::uniform_real_distribution<T> dist2(0, 10);
for (int n = 0; n < 100; ++n)
{
const T value (dist2(rng));
CHECK_ULP_CLOSE(std::log1p(value) - value, boost::math::log1pmx(value), 1e9);
}
CHECK_THROW(boost::math::log1pmx(T(-1.1)), std::domain_error);
CHECK_THROW(boost::math::log1pmx(T(-1.0)), std::overflow_error);
}
int main()