Skip to content

Commit

Permalink
Fix many, many obvious test bugs (#1212)
Browse files Browse the repository at this point in the history
Needed for tests to pass with 128 bit long double types

Co-authored-by: Reimar Döffinger <reimar.doeffinger@arm.com>
  • Loading branch information
rdoeffinger and Reimar Döffinger authored Oct 16, 2024
1 parent 5970659 commit a428222
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 87 deletions.
4 changes: 1 addition & 3 deletions test/ccmath_abs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ int main()

// Types that are convertible to int
test<short>();
#if CHAR_MIN != 0
test<char>();
#endif
test<signed char>();

// fabs
fabs_test<float>();
Expand Down
1 change: 1 addition & 0 deletions test/ccmath_isinf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <cmath>
#include <cfloat>
#include <cstdint>
#include <limits>
#include <boost/math/ccmath/isinf.hpp>
#include <boost/core/lightweight_test.hpp>
Expand Down
1 change: 1 addition & 0 deletions test/ccmath_sqrt_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <cmath>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <boost/math/ccmath/sqrt.hpp>
Expand Down
12 changes: 6 additions & 6 deletions test/daubechies_scaling_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ void test_first_derivative()
// Limited precision test data means we can't test long double here...
#else
auto phi1_3 = boost::math::detail::daubechies_scaling_integer_grid<long double, 3, 1>();
std::array<long double, 6> lin_3{0.0L, 1.638452340884085725014976L, -2.232758190463137395017742L,
0.5501593582740176149905562L, 0.04414649130503405501220997L, 0.0L};
std::array<long double, 6> lin_3{0.0L, 1.638452340884085725014976113635604107L, -2.23275819046313739501774225255380757L,
0.550159358274017614990556164200803310L, 0.044146491305034055012209974717400368L, 0.0L};
for (size_t i = 0; i < lin_3.size(); ++i)
{
if(!CHECK_ULP_CLOSE(lin_3[i], phi1_3[i], 0))
Expand All @@ -308,8 +308,8 @@ void test_first_derivative()
}

auto phi1_4 = boost::math::detail::daubechies_scaling_integer_grid<long double, 4, 1>();
std::array<long double, 8> lin_4 = {0.0L, 1.776072007522184640093776L, -2.785349397229543142492785L, 1.192452536632278174347632L,
-0.1313745151846729587935189L, -0.05357102822023923595359996L,0.001770396479992522798495351L, 0.0L};
std::array<long double, 8> lin_4 = {0.0L, 1.776072007522184640093776071522502761L, -2.785349397229543142492784905731245880L, 1.192452536632278174347632339082851360L,
-0.131374515184672958793518896272545740L, -0.053571028220239235953599959390993709L,0.001770396479992522798495350789431024L, 0.0L};

for (size_t i = 0; i < lin_4.size(); ++i)
{
Expand All @@ -319,8 +319,8 @@ void test_first_derivative()
}
}

std::array<long double, 10> lin_5 = {0.0L, 1.558326313047001366564379L, -2.436012783189551921436896L, 1.235905129801454293947039L, -0.3674377136938866359947561L,
-0.02178035117564654658884556L,0.03234719350814368885815854L,-0.001335619912770701035229331L,-0.00001216838474354431384970525L,0.0L};
std::array<long double, 10> lin_5 = {0.0L, 1.558326313047001366564379221011472479L, -2.436012783189551921436895932290077033L, 1.235905129801454293947038906779457610L, -0.367437713693886635994756136622838186L,
-0.021780351175646546588845564309594589L,0.032347193508143688858158541500450925L,-0.001335619912770701035229330817898250L,-0.000012168384743544313849705250972915L,0.0L};
auto phi1_5 = boost::math::detail::daubechies_scaling_integer_grid<long double, 5, 1>();
for (size_t i = 0; i < lin_5.size(); ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion test/test_airy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void test_airy(T, const char* name)
}};

T tol = boost::math::tools::epsilon<T>() * 800;
if ((std::numeric_limits<T>::digits > 100) || (std::numeric_limits<T>::digits == 0))
if (boost::math::tools::digits<T>() > 100)
tol *= 2;

#ifdef SYCL_LANGUAGE_VERSION
Expand Down
13 changes: 12 additions & 1 deletion test/test_autodiff_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,17 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(asinh_test, T, bin_float_types) {
-39 / (16 * boost::math::constants::root_two<T>()), eps);
}

template<typename T>
static T atan2_wrap(T x, T y)
{
return atan2(x, y);
}

static long double atan2_wrap(long double x, long double y)
{
return std::atan2(x, y);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(atan2_function, T, all_float_types) {
using test_constants = test_constants_t<T>;
using std::atan2;
Expand All @@ -536,7 +547,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(atan2_function, T, all_float_types) {
auto y = y_sampler.next();

auto autodiff_v = atan2(make_fvar<T, m>(x), make_fvar<T, m>(y));
auto anchor_v = atan2(x, y);
auto anchor_v = atan2_wrap(x, y);
BOOST_CHECK_CLOSE(autodiff_v, anchor_v,
5000 * test_constants::pct_epsilon());
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void test_spots(T)
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))
if (boost::math::tools::digits<T>() < 100)
{
// 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);
Expand Down
4 changes: 2 additions & 2 deletions test/test_float_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ T generate_random()
val += gen();
}
e_type e;
val = frexp(val, &e);
val = std::frexp(val, &e);

static boost::random::uniform_int_distribution<e_type> ui(0, std::numeric_limits<T>::max_exponent - 10);
return ldexp(val, ui(gen));
return std::ldexp(val, ui(gen));
}

template <class T>
Expand Down
44 changes: 21 additions & 23 deletions test/test_owens_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,28 @@ void test_spots(RealType)
using ::boost::math::normal_distribution;
BOOST_MATH_STD_USING // ADL of std names.

if(std::numeric_limits<RealType>::digits && (std::numeric_limits<RealType>::digits < 100))
{

// Checks of six sub-methods T1 to T6.
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.0625L), static_cast<RealType>(0.25L)), static_cast<RealType>(3.89119302347013668966224771378e-2L), tolerance); // T1
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(6.5L), static_cast<RealType>(0.4375L)), static_cast<RealType>(2.00057730485083154100907167685E-11L), tolerance); // T2
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(7L), static_cast<RealType>(0.96875L)), static_cast<RealType>(6.39906271938986853083219914429E-13L), tolerance); // T3
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(4.78125L), static_cast<RealType>(0.0625L)), static_cast<RealType>(1.06329748046874638058307112826E-7L), tolerance); // T4
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(2.L), static_cast<RealType>(0.5L)), static_cast<RealType>(8.62507798552150713113488319155E-3L), tolerance); // T5
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(1.L), static_cast<RealType>(0.9999975L)), static_cast<RealType>(6.67418089782285927715589822405E-2L), tolerance); // T6
//BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(L), static_cast<RealType>(L)), static_cast<RealType>(L), tolerance);

// BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(L), static_cast<RealType>(L)), static_cast<RealType>(L), tolerance);

// Spots values using Mathematica
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(6.5L), static_cast<RealType>(0.4375L)), static_cast<RealType>(2.00057730485083154100907167684918851101649922551817956120806662022118024594547E-11L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.4375L), static_cast<RealType>(6.5L)), static_cast<RealType>(0.16540130125449396247498691826626273249659241838438244251206819782787761751256L), tolerance);
// Checks of six sub-methods T1 to T6.
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.0625L), static_cast<RealType>(0.25L)), static_cast<RealType>(3.89119302347013668966224771378499505568e-2L), tolerance); // T1
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(6.5L), static_cast<RealType>(0.4375L)), static_cast<RealType>(2.00057730485083154100907167684918851101649922551817956120806662022118025e-11L), tolerance); // T2
if (boost::math::tools::digits<RealType>() < 100) // too large error for 128 bit long double
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(7L), static_cast<RealType>(0.96875L)), static_cast<RealType>(6.3990627193898685308321991442891601376479719094145923322318222572484602e-13L), tolerance); // T3
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(4.78125L), static_cast<RealType>(0.0625L)), static_cast<RealType>(1.06329748046874638058307112826015825291136503488102191050906959246644943e-7L), tolerance); // T4
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(2.L), static_cast<RealType>(0.5L)), static_cast<RealType>(8.6250779855215071311348831915463718787564119039085429110080944948781288e-3L), tolerance); // T5
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(1.L), static_cast<RealType>(0.9999975L)), static_cast<RealType>(6.6741808978228592771558982240461689232406934240709035854119334966793020e-2L), tolerance); // T6
//BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(L), static_cast<RealType>(L)), static_cast<RealType>(L), tolerance);

// BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(L), static_cast<RealType>(L)), static_cast<RealType>(L), tolerance);

// Spots values using Mathematica
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(6.5L), static_cast<RealType>(0.4375L)), static_cast<RealType>(2.00057730485083154100907167684918851101649922551817956120806662022118024594547E-11L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.4375L), static_cast<RealType>(6.5L)), static_cast<RealType>(0.16540130125449396247498691826626273249659241838438244251206819782787761751256L), tolerance);
if (boost::math::tools::digits<RealType>() < 100) // too large error for 128 bit long double
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(7.L), static_cast<RealType>(0.96875L)), static_cast<RealType>(6.39906271938986853083219914428916013764797190941459233223182225724846022843930e-13L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.96875L), static_cast<RealType>(7.L)), static_cast<RealType>(0.08316748474602973770533230453272140919966614259525787470390475393923633179072L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(4.78125L), static_cast<RealType>(0.0625L)), static_cast<RealType>(1.06329748046874638058307112826015825291136503488102191050906959246644942646701e-7L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.0625L), static_cast<RealType>(4.78125L)), static_cast<RealType>(0.21571185819897989857261253680409017017649352928888660746045361855686569265171L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(2.L), static_cast<RealType>(0.5L)), static_cast<RealType>(0.00862507798552150713113488319154637187875641190390854291100809449487812876461L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.5L), static_cast<RealType>(2L)), static_cast<RealType>(0.14158060365397839346662819588111542648867283386549027383784843786494855594607L), tolerance);
}
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.96875L), static_cast<RealType>(7.L)), static_cast<RealType>(0.08316748474602973770533230453272140919966614259525787470390475393923633179072L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(4.78125L), static_cast<RealType>(0.0625L)), static_cast<RealType>(1.06329748046874638058307112826015825291136503488102191050906959246644942646701e-7L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.0625L), static_cast<RealType>(4.78125L)), static_cast<RealType>(0.21571185819897989857261253680409017017649352928888660746045361855686569265171L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(2.L), static_cast<RealType>(0.5L)), static_cast<RealType>(0.00862507798552150713113488319154637187875641190390854291100809449487812876461L), tolerance);
BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast<RealType>(0.5L), static_cast<RealType>(2L)), static_cast<RealType>(0.14158060365397839346662819588111542648867283386549027383784843786494855594607L), tolerance);
// check basic properties
BOOST_CHECK_EQUAL(owens_t(static_cast<RealType>(0.5L), static_cast<RealType>(2L)), owens_t(static_cast<RealType>(-0.5L), static_cast<RealType>(2L)));
BOOST_CHECK_EQUAL(owens_t(static_cast<RealType>(0.5L), static_cast<RealType>(2L)), -owens_t(static_cast<RealType>(0.5L), static_cast<RealType>(-2L)));
Expand Down
Loading

0 comments on commit a428222

Please sign in to comment.