From a4282229f5db14f4ad0b98917afdddd12ee2afd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 16 Oct 2024 17:16:12 +0200 Subject: [PATCH] Fix many, many obvious test bugs (#1212) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Needed for tests to pass with 128 bit long double types Co-authored-by: Reimar Döffinger --- test/ccmath_abs_test.cpp | 4 +- test/ccmath_isinf_test.cpp | 1 + test/ccmath_sqrt_test.cpp | 1 + test/daubechies_scaling_test.cpp | 12 ++--- test/test_airy.cpp | 2 +- test/test_autodiff_2.cpp | 13 ++++- test/test_beta.hpp | 2 +- test/test_float_io.cpp | 4 +- test/test_owens_t.hpp | 44 ++++++++------- test/test_skew_normal.cpp | 91 ++++++++++++++------------------ 10 files changed, 87 insertions(+), 87 deletions(-) diff --git a/test/ccmath_abs_test.cpp b/test/ccmath_abs_test.cpp index 467b7a5a15..6f09b3e0b3 100644 --- a/test/ccmath_abs_test.cpp +++ b/test/ccmath_abs_test.cpp @@ -76,9 +76,7 @@ int main() // Types that are convertible to int test(); -#if CHAR_MIN != 0 - test(); -#endif + test(); // fabs fabs_test(); diff --git a/test/ccmath_isinf_test.cpp b/test/ccmath_isinf_test.cpp index 1f6b61d2fa..3ee5d1375a 100644 --- a/test/ccmath_isinf_test.cpp +++ b/test/ccmath_isinf_test.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/test/ccmath_sqrt_test.cpp b/test/ccmath_sqrt_test.cpp index af2911bb85..eb2cf039dc 100644 --- a/test/ccmath_sqrt_test.cpp +++ b/test/ccmath_sqrt_test.cpp @@ -4,6 +4,7 @@ // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include #include #include #include diff --git a/test/daubechies_scaling_test.cpp b/test/daubechies_scaling_test.cpp index 3fd0937ece..e2dda727e4 100644 --- a/test/daubechies_scaling_test.cpp +++ b/test/daubechies_scaling_test.cpp @@ -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(); - std::array lin_3{0.0L, 1.638452340884085725014976L, -2.232758190463137395017742L, - 0.5501593582740176149905562L, 0.04414649130503405501220997L, 0.0L}; + std::array 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)) @@ -308,8 +308,8 @@ void test_first_derivative() } auto phi1_4 = boost::math::detail::daubechies_scaling_integer_grid(); - std::array lin_4 = {0.0L, 1.776072007522184640093776L, -2.785349397229543142492785L, 1.192452536632278174347632L, - -0.1313745151846729587935189L, -0.05357102822023923595359996L,0.001770396479992522798495351L, 0.0L}; + std::array 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) { @@ -319,8 +319,8 @@ void test_first_derivative() } } - std::array lin_5 = {0.0L, 1.558326313047001366564379L, -2.436012783189551921436896L, 1.235905129801454293947039L, -0.3674377136938866359947561L, - -0.02178035117564654658884556L,0.03234719350814368885815854L,-0.001335619912770701035229331L,-0.00001216838474354431384970525L,0.0L}; + std::array 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(); for (size_t i = 0; i < lin_5.size(); ++i) { diff --git a/test/test_airy.cpp b/test/test_airy.cpp index 548d4de159..335c5fd92c 100644 --- a/test/test_airy.cpp +++ b/test/test_airy.cpp @@ -55,7 +55,7 @@ void test_airy(T, const char* name) }}; T tol = boost::math::tools::epsilon() * 800; - if ((std::numeric_limits::digits > 100) || (std::numeric_limits::digits == 0)) + if (boost::math::tools::digits() > 100) tol *= 2; #ifdef SYCL_LANGUAGE_VERSION diff --git a/test/test_autodiff_2.cpp b/test/test_autodiff_2.cpp index 79ee24ba0d..7315e7dc1b 100644 --- a/test/test_autodiff_2.cpp +++ b/test/test_autodiff_2.cpp @@ -522,6 +522,17 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(asinh_test, T, bin_float_types) { -39 / (16 * boost::math::constants::root_two()), eps); } +template +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; using std::atan2; @@ -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(x), make_fvar(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()); } diff --git a/test/test_beta.hpp b/test/test_beta.hpp index 3019c17e71..362bf51bf2 100644 --- a/test/test_beta.hpp +++ b/test/test_beta.hpp @@ -105,7 +105,7 @@ void test_spots(T) BOOST_CHECK_CLOSE(::boost::math::beta(small, static_cast(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(4), static_cast(20)), static_cast(0.00002823263692828910220214568040654997176736L), tolerance); - if ((std::numeric_limits::digits < 100) && (std::numeric_limits::digits != 0)) + if (boost::math::tools::digits() < 100) { // Inexact input, so disable for ultra precise long doubles: BOOST_CHECK_CLOSE(::boost::math::beta(static_cast(0.0125L), static_cast(0.000023L)), static_cast(43558.24045647538375006349016083320744662L), tolerance * 2); diff --git a/test/test_float_io.cpp b/test/test_float_io.cpp index e1b5c67a12..4c1ee1760a 100644 --- a/test/test_float_io.cpp +++ b/test/test_float_io.cpp @@ -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 ui(0, std::numeric_limits::max_exponent - 10); - return ldexp(val, ui(gen)); + return std::ldexp(val, ui(gen)); } template diff --git a/test/test_owens_t.hpp b/test/test_owens_t.hpp index 995446e5fd..a65ba4af94 100644 --- a/test/test_owens_t.hpp +++ b/test/test_owens_t.hpp @@ -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::digits && (std::numeric_limits::digits < 100)) - { - - // Checks of six sub-methods T1 to T6. - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.0625L), static_cast(0.25L)), static_cast(3.89119302347013668966224771378e-2L), tolerance); // T1 - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(6.5L), static_cast(0.4375L)), static_cast(2.00057730485083154100907167685E-11L), tolerance); // T2 - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(7L), static_cast(0.96875L)), static_cast(6.39906271938986853083219914429E-13L), tolerance); // T3 - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(4.78125L), static_cast(0.0625L)), static_cast(1.06329748046874638058307112826E-7L), tolerance); // T4 - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(2.L), static_cast(0.5L)), static_cast(8.62507798552150713113488319155E-3L), tolerance); // T5 - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(1.L), static_cast(0.9999975L)), static_cast(6.67418089782285927715589822405E-2L), tolerance); // T6 - //BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(L), static_cast(L)), static_cast(L), tolerance); - - // BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(L), static_cast(L)), static_cast(L), tolerance); - - // Spots values using Mathematica - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(6.5L), static_cast(0.4375L)), static_cast(2.00057730485083154100907167684918851101649922551817956120806662022118024594547E-11L), tolerance); - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.4375L), static_cast(6.5L)), static_cast(0.16540130125449396247498691826626273249659241838438244251206819782787761751256L), tolerance); + // Checks of six sub-methods T1 to T6. + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.0625L), static_cast(0.25L)), static_cast(3.89119302347013668966224771378499505568e-2L), tolerance); // T1 + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(6.5L), static_cast(0.4375L)), static_cast(2.00057730485083154100907167684918851101649922551817956120806662022118025e-11L), tolerance); // T2 + if (boost::math::tools::digits() < 100) // too large error for 128 bit long double + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(7L), static_cast(0.96875L)), static_cast(6.3990627193898685308321991442891601376479719094145923322318222572484602e-13L), tolerance); // T3 + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(4.78125L), static_cast(0.0625L)), static_cast(1.06329748046874638058307112826015825291136503488102191050906959246644943e-7L), tolerance); // T4 + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(2.L), static_cast(0.5L)), static_cast(8.6250779855215071311348831915463718787564119039085429110080944948781288e-3L), tolerance); // T5 + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(1.L), static_cast(0.9999975L)), static_cast(6.6741808978228592771558982240461689232406934240709035854119334966793020e-2L), tolerance); // T6 + //BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(L), static_cast(L)), static_cast(L), tolerance); + + // BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(L), static_cast(L)), static_cast(L), tolerance); + + // Spots values using Mathematica + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(6.5L), static_cast(0.4375L)), static_cast(2.00057730485083154100907167684918851101649922551817956120806662022118024594547E-11L), tolerance); + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.4375L), static_cast(6.5L)), static_cast(0.16540130125449396247498691826626273249659241838438244251206819782787761751256L), tolerance); + if (boost::math::tools::digits() < 100) // too large error for 128 bit long double BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(7.L), static_cast(0.96875L)), static_cast(6.39906271938986853083219914428916013764797190941459233223182225724846022843930e-13L), tolerance); - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.96875L), static_cast(7.L)), static_cast(0.08316748474602973770533230453272140919966614259525787470390475393923633179072L), tolerance); - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(4.78125L), static_cast(0.0625L)), static_cast(1.06329748046874638058307112826015825291136503488102191050906959246644942646701e-7L), tolerance); - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.0625L), static_cast(4.78125L)), static_cast(0.21571185819897989857261253680409017017649352928888660746045361855686569265171L), tolerance); - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(2.L), static_cast(0.5L)), static_cast(0.00862507798552150713113488319154637187875641190390854291100809449487812876461L), tolerance); - BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.5L), static_cast(2L)), static_cast(0.14158060365397839346662819588111542648867283386549027383784843786494855594607L), tolerance); - } + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.96875L), static_cast(7.L)), static_cast(0.08316748474602973770533230453272140919966614259525787470390475393923633179072L), tolerance); + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(4.78125L), static_cast(0.0625L)), static_cast(1.06329748046874638058307112826015825291136503488102191050906959246644942646701e-7L), tolerance); + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.0625L), static_cast(4.78125L)), static_cast(0.21571185819897989857261253680409017017649352928888660746045361855686569265171L), tolerance); + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(2.L), static_cast(0.5L)), static_cast(0.00862507798552150713113488319154637187875641190390854291100809449487812876461L), tolerance); + BOOST_CHECK_CLOSE_FRACTION(owens_t(static_cast(0.5L), static_cast(2L)), static_cast(0.14158060365397839346662819588111542648867283386549027383784843786494855594607L), tolerance); // check basic properties BOOST_CHECK_EQUAL(owens_t(static_cast(0.5L), static_cast(2L)), owens_t(static_cast(-0.5L), static_cast(2L))); BOOST_CHECK_EQUAL(owens_t(static_cast(0.5L), static_cast(2L)), -owens_t(static_cast(0.5L), static_cast(-2L))); diff --git a/test/test_skew_normal.cpp b/test/test_skew_normal.cpp index 5f0657fbd1..617a8f6fab 100644 --- a/test/test_skew_normal.cpp +++ b/test/test_skew_normal.cpp @@ -356,7 +356,7 @@ void test_spots(RealType) BOOST_CHECK_CLOSE( // mean: mean(dist) - , static_cast(-0.579908992539856825862549L), tol10 * 2); + , static_cast(-0.5799089925398568258625490172876619L), tol10 * 2); std::cout << std::setprecision(17) << "Variance = " << variance(dist) << std::endl; BOOST_CHECK_CLOSE( // variance: N[variance[skewnormaldistribution[1.1, 2.2, -3.3]], 50] @@ -365,27 +365,27 @@ void test_spots(RealType) BOOST_CHECK_CLOSE( // skewness: skewness(dist) - , static_cast(-0.709854548171537509192897824663L), tol100); + , static_cast(-0.709854548171537509192897824663027155L), tol100); BOOST_CHECK_CLOSE( // kurtosis: kurtosis(dist) - , static_cast(3.5538752625241790601377L), tol100); + , static_cast(3.55387526252417906013770535120683805L), tol100); BOOST_CHECK_CLOSE( // kurtosis excess: kurtosis_excess(dist) - , static_cast(0.5538752625241790601377L), tol100); + , static_cast(0.553875262524179060137705351206838143L), tol100); BOOST_CHECK_CLOSE( pdf(dist, static_cast(0.4L)), - static_cast(0.294140110156599539564571L), + static_cast(0.294140110156599539564571034730246656L), tol10); BOOST_CHECK_CLOSE( cdf(dist, static_cast(0.4L)), - static_cast(0.7339186189278737976326676452L), + static_cast(0.733918618927873797632667645226588243L), tol100); BOOST_CHECK_CLOSE( quantile(dist, static_cast(0.3L)), - static_cast(-1.180104068086875314419247L), + static_cast(-1.18010406808687531441924729956233392L), tol100); @@ -395,72 +395,63 @@ void test_spots(RealType) // cout << "pdf(dist, 0) = " << pdf(dist, 0) << ", pdf(dist, 0.45) = " << pdf(dist, 0.45) << endl; // BOOST_CHECK_CLOSE(mode(dist), boost::math::constants::root_two() / 2, tol5); - BOOST_CHECK_CLOSE(mode(dist), static_cast(0.41697299497388863932L), tol100); + BOOST_CHECK_CLOSE(mode(dist), static_cast(0.416972994973888639318345129445233074L), tol100); } } - if(std::numeric_limits< RealType>::digits && (std::numeric_limits::digits < 100)) - { - dist = skew_normal_distribution(static_cast(1.1l), static_cast(0.02l), static_cast(0.03l)); + dist = skew_normal_distribution(static_cast(1.1l), static_cast(0.02l), static_cast(0.03l)); - BOOST_CHECK_CLOSE( // mean: + BOOST_CHECK_CLOSE( // mean: mean(dist) - , static_cast(1.1004785154529557886162L), tol10); - BOOST_CHECK_CLOSE( // variance: + , static_cast(1.1004785154529557886162056250600829L), tol10); + BOOST_CHECK_CLOSE( // variance: variance(dist) - , static_cast(0.00039977102296128251645L), tol10); + , static_cast(0.000399771022961282516451686289719995601L), tol10); - BOOST_CHECK_CLOSE( // skewness: + BOOST_CHECK_CLOSE( // skewness: skewness(dist) - , static_cast(5.8834811259890359782e-006L), tol100); - BOOST_CHECK_CLOSE( // kurtosis: + , static_cast(5.88348112598903597820852388986073439e-006L), tol100); + BOOST_CHECK_CLOSE( // kurtosis: kurtosis(dist) - , static_cast(3.L + 9.2903475812137800239002e-008L), tol100); - BOOST_CHECK_CLOSE( // kurtosis excess: + , static_cast(3.L + 9.290347581213780023900209941e-008L), tol100); + BOOST_CHECK_CLOSE( // kurtosis excess: kurtosis_excess(dist) - , static_cast(9.2903475812137800239002e-008L), tol100); - } - if (std::numeric_limits< RealType>::digits && (std::numeric_limits::digits < 100)) - { - dist = skew_normal_distribution(static_cast(10.1l), static_cast(5.l), static_cast(-0.03l)); - BOOST_CHECK_CLOSE( // mean: + , static_cast(9.29034758121378002390020993765449518e-008L), tol100); + dist = skew_normal_distribution(static_cast(10.1l), static_cast(5.l), static_cast(-0.03l)); + BOOST_CHECK_CLOSE( // mean: mean(dist) - , static_cast(9.9803711367610528459485937L), tol10); - BOOST_CHECK_CLOSE( // variance: + , static_cast(9.98037113676105284594859373497928476L), tol10); + BOOST_CHECK_CLOSE( // variance: variance(dist) - , static_cast(24.98568893508015727823L), tol10); + , static_cast(24.9856889350801572782303931074997234L), tol10); - BOOST_CHECK_CLOSE( // skewness: + BOOST_CHECK_CLOSE( // skewness: skewness(dist) - , static_cast(-5.8834811259890359782085e-006L), tol100); - BOOST_CHECK_CLOSE( // kurtosis: + , static_cast(-5.88348112598903597820852388986073439e-006L), tol100); + BOOST_CHECK_CLOSE( // kurtosis: kurtosis(dist) - , static_cast(3.L + 9.2903475812137800239002e-008L), tol100); - BOOST_CHECK_CLOSE( // kurtosis excess: + , static_cast(3.L + 9.290347581213780023900209941e-008L), tol100); + BOOST_CHECK_CLOSE( // kurtosis excess: kurtosis_excess(dist) - , static_cast(9.2903475812137800239002e-008L), tol100); - } - if (std::numeric_limits< RealType>::digits && (std::numeric_limits::digits < 100)) - { - dist = skew_normal_distribution(static_cast(-10.1l), static_cast(5.l), static_cast(30.l)); - BOOST_CHECK_CLOSE( // mean: + , static_cast(9.29034758121378002390020993765449518e-008L), tol100); + dist = skew_normal_distribution(static_cast(-10.1l), static_cast(5.l), static_cast(30.l)); + BOOST_CHECK_CLOSE( // mean: mean(dist) - , static_cast(-6.11279169674138408531365L), 2 * tol10); - BOOST_CHECK_CLOSE( // variance: + , static_cast(-6.11279169674138408531365149047090859L), 2 * tol10); + BOOST_CHECK_CLOSE( // variance: variance(dist) - , static_cast(9.10216994642554914628242L), tol10 * 2); + , static_cast(9.10216994642554914628242097277880642L), tol10 * 2); - BOOST_CHECK_CLOSE( // skewness: + BOOST_CHECK_CLOSE( // skewness: skewness(dist) - , static_cast(0.99072425443686904424L), tol100); - BOOST_CHECK_CLOSE( // kurtosis: + , static_cast(0.990724254436869044244695246354219556L), tol100); + BOOST_CHECK_CLOSE( // kurtosis: kurtosis(dist) - , static_cast(3.L + 0.8638862008406084244563L), tol100); - BOOST_CHECK_CLOSE( // kurtosis excess: + , static_cast(3.L + 0.8638862008406084244563090239530549L), tol100); + BOOST_CHECK_CLOSE( // kurtosis excess: kurtosis_excess(dist) - , static_cast(0.8638862008406084244563L), tol100); - } + , static_cast(0.863886200840608424456309023953054896L), tol100); BOOST_MATH_CHECK_THROW(cdf(skew_normal_distribution(0, 0, 0), 0), std::domain_error); BOOST_MATH_CHECK_THROW(cdf(skew_normal_distribution(0, -1, 0), 0), std::domain_error);