From 695c3957d16df758ff8baf2b27c6188da1910f22 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Fri, 27 Jun 2025 14:13:55 +0200 Subject: [PATCH] Address review comments for tests --- performance/performance_test_df.cpp | 3 +- test/concepts/sf_concept_check_basic.cpp | 4 +- test/concepts/sf_concept_check_bessel.cpp | 4 +- test/test.hpp | 51 ++++++++---- test/test_complex.cpp | 11 --- test/test_cos.cpp | 2 +- test/test_cosh.cpp | 2 +- test/test_exp.cpp | 78 ++++++++++--------- test/test_float_io.cpp | 45 ++++++----- test/test_fpclassify.cpp | 2 +- test/test_log.cpp | 2 +- test/test_numeric_limits.cpp | 9 ++- test/test_pow.cpp | 75 +++++++++++------- test/test_pow_data.hpp | 4 +- ..._data_df.hpp => test_pow_data_reduced.hpp} | 10 +-- test/test_round.cpp | 37 ++++++--- test/test_sf_import_c99.cpp | 21 +++-- test/test_sin.cpp | 2 +- test/test_sinh.cpp | 2 +- test/test_sqrt.cpp | 4 +- test/test_tan.cpp | 2 +- test/test_tanh.cpp | 2 +- 22 files changed, 210 insertions(+), 162 deletions(-) rename test/{test_pow_data_df.hpp => test_pow_data_reduced.hpp} (99%) diff --git a/performance/performance_test_df.cpp b/performance/performance_test_df.cpp index 6251f466..16a8b871 100644 --- a/performance/performance_test_df.cpp +++ b/performance/performance_test_df.cpp @@ -192,7 +192,7 @@ int main() local::test29(); local::test32(); local::test52(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) local::test53(); #endif @@ -251,7 +251,6 @@ void local::test53() #endif } - #if 0 See also: https://github.com/BoostGSoC21/multiprecision/issues/178#issuecomment-2580157139 diff --git a/test/concepts/sf_concept_check_basic.cpp b/test/concepts/sf_concept_check_basic.cpp index a05485dc..fa5abccc 100644 --- a/test/concepts/sf_concept_check_basic.cpp +++ b/test/concepts/sf_concept_check_basic.cpp @@ -165,9 +165,7 @@ void foo() test_extra(num_t()); #endif #ifdef TEST_CPP_DOUBLE_FLOAT - using cpp_double_float_of_double_type = boost::multiprecision::cpp_double_double; - - test_extra(cpp_double_float_of_double_type()); + test_extra(boost::multiprecision::cpp_double_double()); #endif } diff --git a/test/concepts/sf_concept_check_bessel.cpp b/test/concepts/sf_concept_check_bessel.cpp index 27a00eb0..fc2028bc 100644 --- a/test/concepts/sf_concept_check_bessel.cpp +++ b/test/concepts/sf_concept_check_bessel.cpp @@ -132,9 +132,7 @@ void foo() test_extra(num_t()); #endif #ifdef TEST_CPP_DOUBLE_FLOAT - using cpp_double_float_of_double_type = boost::multiprecision::cpp_double_double; - - test_extra(cpp_double_float_of_double_type()); + test_extra(boost::multiprecision::cpp_double_double()); #endif } diff --git a/test/test.hpp b/test/test.hpp index 772cbfbd..2b48c8bc 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -1,5 +1,7 @@ /////////////////////////////////////////////////////////////// -// Copyright 2012 John Maddock. Distributed under the Boost +// Copyright 2012 - 2025 John Maddock. +// Copyright 2025 Christopher Kormanyos. +// Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt // @@ -7,15 +9,23 @@ #ifndef BOOST_MULTIPRECISION_TEST_HPP #define BOOST_MULTIPRECISION_TEST_HPP -#include -#include -#include - #include #include #include #include +#if defined(TEST_CPP_DOUBLE_FLOAT) + +#include + +#include + +#endif // TEST_CPP_DOUBLE_FLOAT + +#include +#include +#include + namespace detail { template @@ -193,7 +203,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) #endif #define BOOST_CHECK_IMP(x, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (x) \ { \ @@ -211,7 +221,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) #define BOOST_REQUIRE(x) BOOST_CHECK_IMP(x, abort_on_fail) #define BOOST_CLOSE_IMP(x, y, tol, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (relative_error(x, y) > tol) \ { \ @@ -228,7 +238,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) #define BOOST_EQUAL_IMP(x, y, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (!((x) == (y))) \ { \ @@ -243,7 +253,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) #define BOOST_NE_IMP(x, y, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (!(x != y)) \ { \ @@ -258,7 +268,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) #define BOOST_LT_IMP(x, y, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (!(x < y)) \ { \ @@ -273,7 +283,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) #define BOOST_GT_IMP(x, y, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (!(x > y)) \ { \ @@ -288,7 +298,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) #define BOOST_LE_IMP(x, y, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (!(x <= y)) \ { \ @@ -303,7 +313,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) #define BOOST_GE_IMP(x, y, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ if (!(x >= y)) \ { \ @@ -319,7 +329,7 @@ std::ostream& operator<<(std::ostream& os, __float128 f) #ifndef BOOST_NO_EXCEPTIONS #define BOOST_MT_CHECK_THROW_IMP(x, E, severity) \ - BOOST_MP_TEST_TRY \ + BOOST_MP_TEST_TRY \ { \ x; \ BOOST_MP_REPORT_WHERE << " Expected exception not thrown in expression " << BOOST_STRINGIZE(x) << std::endl; \ @@ -367,4 +377,17 @@ std::ostream& operator<<(std::ostream& os, __float128 f) #define BOOST_WARN_THROW(x, E) BOOST_MT_CHECK_THROW_IMP(x, E, warn_on_fail) #define BOOST_REQUIRE_THROW(x, E) BOOST_MT_CHECK_THROW_IMP(x, E, abort_on_fail) +#if defined(TEST_CPP_DOUBLE_FLOAT) + +template struct has_poor_exp_range_or_precision_support { static constexpr bool value { false }; }; + +template <> struct has_poor_exp_range_or_precision_support<::boost::multiprecision::cpp_double_float> final { static constexpr bool value { true }; }; +template <> struct has_poor_exp_range_or_precision_support<::boost::multiprecision::cpp_double_double> final { static constexpr bool value { true }; }; +template <> struct has_poor_exp_range_or_precision_support<::boost::multiprecision::cpp_double_long_double> final { static constexpr bool value { true }; }; +#if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) // (which is the same as BOOST_HAS_FLOAT128) +template <> struct has_poor_exp_range_or_precision_support<::boost::multiprecision::cpp_double_float128> final { static constexpr bool value { true }; }; #endif + +#endif // TEST_CPP_DOUBLE_FLOAT + +#endif // BOOST_MULTIPRECISION_TEST_HPP diff --git a/test/test_complex.cpp b/test/test_complex.cpp index d2529d4e..17fded80 100644 --- a/test/test_complex.cpp +++ b/test/test_complex.cpp @@ -9,14 +9,6 @@ // "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations", // in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469 -/////////////////////////////////////////////////////////////////////////////// -// Copyright John Maddock 2016. -// Copyright Christopher Kormanyos 2016 - 2024. -// Distributed under the Boost Software License, -// Version 1.0. (See accompanying file LICENSE_1_0.txt -// or copy at http://www.boost.org/LICENSE_1_0.txt) -// - #include #ifdef TEST_MPC #include @@ -170,8 +162,6 @@ void test() int main() { - -#if !defined(TEST_CPP_DOUBLE_FLOAT) #ifdef TEST_MPC local::test(); local::test(); @@ -181,7 +171,6 @@ int main() #ifdef BOOST_HAS_FLOAT128 local::test(); #endif -#endif #if defined(TEST_CPP_DOUBLE_FLOAT) { diff --git a/test/test_cos.cpp b/test/test_cos.cpp index 80d9d0ac..7c9d0695 100644 --- a/test/test_cos.cpp +++ b/test/test_cos.cpp @@ -403,7 +403,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_cosh.cpp b/test/test_cosh.cpp index 8e72e570..45826ce5 100644 --- a/test/test_cosh.cpp +++ b/test/test_cosh.cpp @@ -190,7 +190,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_exp.cpp b/test/test_exp.cpp index 450b39da..b2cf9258 100644 --- a/test/test_exp.cpp +++ b/test/test_exp.cpp @@ -62,9 +62,6 @@ #include #endif #ifdef TEST_CPP_DOUBLE_FLOAT -#if defined(BOOST_MATH_USE_FLOAT128) -#include -#endif #include #endif @@ -72,10 +69,13 @@ template void test() { std::cout << "Testing type " << typeid(T).name() << std::endl; + unsigned max_err = 0; -#if !defined(TEST_CPP_DOUBLE_FLOAT) // exponent range in tabulated data is too large for these types. - static const std::array data = - {{ + + BOOST_IF_CONSTEXPR (!::has_poor_exp_range_or_precision_support::value) + { + static const std::array data = + {{ "1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "9.47747587596218770242116751705184563668845029215054154915126374673142219159548534317576897266130328412495991561490384353e76", "8.98225489794452370997623936390755615068333094834545092387689795875746440121970819499035111276893290879203289092353747850e153", @@ -127,43 +127,44 @@ void test() "7.60762342267101369970765191988545810374824800500875923752736467467657167098026707905341603949108433696304383346239333297e3694", "7.21010674617694221027190468649359000420209460539838589305387835463807416706224777302997789297329446308541513638035437482e3771", "6.83336127500041943234365059231968669406267422759442985746460610830503287734479988530512309065240678799786759250323660701e3848", - }}; + }}; - T pi = static_cast("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609"); + T pi = static_cast("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609"); - for (unsigned k = 0; k < data.size(); k++) - { - T val = exp(sqrt((pi * (100 * k)) * (100 * k))); - T e = relative_error(val, T(data[k])); - unsigned err = e.template convert_to(); - if (err > max_err) + for (unsigned k = 0; k < data.size(); k++) { - max_err = err; + T val = exp(sqrt((pi * (100 * k)) * (100 * k))); + T e = relative_error(val, T(data[k])); + unsigned err = e.template convert_to(); + if (err > max_err) + { + max_err = err; + } + val = exp(-sqrt((pi * (100 * k)) * (100 * k))); + e = relative_error(val, T(1 / T(data[k]))); + err = e.template convert_to(); + if (err > max_err) + { + max_err = err; + } } - val = exp(-sqrt((pi * (100 * k)) * (100 * k))); - e = relative_error(val, T(1 / T(data[k]))); - err = e.template convert_to(); - if (err > max_err) - { - max_err = err; - } - } - std::cout << "Max error was: " << max_err << std::endl; + std::cout << "Max error was: " << max_err << std::endl; #if defined(BOOST_INTEL) && defined(TEST_FLOAT128) - BOOST_TEST(max_err < 40000); + BOOST_TEST(max_err < 40000); #elif defined(TEST_CPP_BIN_FLOAT) - BOOST_TEST(max_err < 6200); + BOOST_TEST(max_err < 6200); #else - BOOST_TEST(max_err < 5000); + BOOST_TEST(max_err < 5000); #endif + } // !::has_poor_exp_range_or_precision_support::value -#endif // !defined(TEST_CPP_DOUBLE_FLOAT) + using std::ldexp; static const std::array, 12> exact_data = {{ - {{std::ldexp(1.0, -50), static_cast("1.000000000000000888178419700125626769357944978675730736309709508287711059579809241499236575743374705946980126761002249532899810120773330275600867188192232364653350140592709328919189811425580736404494785")}}, - {{std::ldexp(1.0, -20), static_cast("1.00000095367477115374544678824955687428365188553281789775169686343569285229334215539516690752571791280462887427635269562079697496032436580742164524046357050365736415701568566320292733574692386949329504")}}, - {{std::ldexp(1.0, -10), static_cast("1.00097703949241653524284529261160650646585162918174419940186408264916250428896869173656853690882467186075613761065459260696969179898943231122954769049191889764955875334240964352999872451396042953452219")}}, + {{ldexp(1.0, -50), static_cast("1.000000000000000888178419700125626769357944978675730736309709508287711059579809241499236575743374705946980126761002249532899810120773330275600867188192232364653350140592709328919189811425580736404494785")}}, + {{ldexp(1.0, -20), static_cast("1.00000095367477115374544678824955687428365188553281789775169686343569285229334215539516690752571791280462887427635269562079697496032436580742164524046357050365736415701568566320292733574692386949329504")}}, + {{ldexp(1.0, -10), static_cast("1.00097703949241653524284529261160650646585162918174419940186408264916250428896869173656853690882467186075613761065459260696969179898943231122954769049191889764955875334240964352999872451396042953452219")}}, {{0.25, static_cast("1.28402541668774148407342056806243645833628086528146308921750729687220776586723800275330641943955356890166283174967968730585475423604648842750177989872959231004569930548795441439028562847893962382677678")}}, {{0.5, static_cast("1.64872127070012814684865078781416357165377610071014801157507931164066102119421560863277652005636664300286663775630779700467116697521960915984097145249005979692942265909840391471994846465948924489686891")}}, {{0.75, static_cast("2.11700001661267466854536981983709561013449158470240342177913303081098453336401282000279156026661579821888590471901551426235852033897220601942873096478507538156877637403469865756763918374951675146515683")}}, @@ -213,12 +214,15 @@ void test() } } - #if defined(TEST_CPP_DOUBLE_FLOAT) // Handle uneven/asymmetric exponents on min/max of cpp_double_fp_backend - bug_case = log(1 / (std::numeric_limits::min)()) / -1.0005; - #else - bug_case = log((std::numeric_limits::max)()) / -1.0005; - #endif + BOOST_IF_CONSTEXPR (::has_poor_exp_range_or_precision_support::value) + { + bug_case = log(1 / (std::numeric_limits::min)()) / -1.0005; + } + else + { + bug_case = log((std::numeric_limits::max)()) / -1.0005; + } unsigned i { 0U }; @@ -275,7 +279,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_float_io.cpp b/test/test_float_io.cpp index 9135058c..8265ed6a 100644 --- a/test/test_float_io.cpp +++ b/test/test_float_io.cpp @@ -6,6 +6,9 @@ // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt // +#define TEST_CPP_DEC_FLOAT +#define TEST_CPP_DOUBLE_FLOAT + #ifdef _MSC_VER #define _SCL_SECURE_NO_WARNINGS #endif @@ -118,7 +121,10 @@ void print_flags(std::ios_base::fmtflags f) template void test() { - typedef T mp_t; + typedef T mp_t; + + std::cout << "Testing type of test: " << typeid(mp_t).name() << std::endl; + std::array f = {{std::ios_base::fmtflags(0), std::ios_base::showpoint, std::ios_base::showpos, std::ios_base::scientific, std::ios_base::scientific | std::ios_base::showpos, std::ios_base::scientific | std::ios_base::showpoint, std::ios_base::fixed, std::ios_base::fixed | std::ios_base::showpoint, @@ -145,17 +151,10 @@ void test() const char* expect = string_data[j][col]; if (ss.str() != expect) { - #if defined(TEST_CPP_DOUBLE_FLOAT) - if (has_bad_bankers_rounding(mp_t())) - { - std::cout << "Ignoring bankers-rounding error with TEST_CPP_DOUBLE_FLOAT.\n"; - } - #else if (has_bad_bankers_rounding(mp_t()) && is_bankers_rounding_error(ss.str(), expect)) { - std::cout << "Ignoring bankers-rounding error with GMP mp_f.\n"; + std::cout << "Ignoring bankers-rounding error with " << typeid(T).name() << ".\n"; } - #endif else { std::cout << std::setprecision(20) << "Testing value " << val << std::endl; @@ -252,22 +251,22 @@ T generate_random() e_type e; val = frexp(val, &e); - #if defined(TEST_CPP_DOUBLE_FLOAT) constexpr auto exp_range = - static_cast - ( - static_cast + (::has_poor_exp_range_or_precision_support::value) + ? static_cast ( - static_cast(std::numeric_limits::max_exponent10) - - static_cast(static_cast(std::numeric_limits::max_digits10) * 1.1F) + static_cast + ( + static_cast(std::numeric_limits::max_exponent10) + - static_cast(static_cast(std::numeric_limits::max_digits10) * 1.1F) + ) + / 0.301F ) - / 0.301F - ); - #else - constexpr auto exp_range = std::numeric_limits::max_exponent - 10; - #endif + : std::numeric_limits::max_exponent - 10 + ; static boost::random::uniform_int_distribution ui(0, exp_range); + return ldexp(val, ui(gen)); } @@ -325,6 +324,8 @@ void do_round_trip(const T& val) template void test_round_trip() { + std::cout << "Testing type of test_round_trip: " << typeid(T).name() << std::endl; + for (unsigned i = 0; i < 1000; ++i) { T val = generate_random(); @@ -338,6 +339,8 @@ void test_round_trip() template void test_to_string() { + std::cout << "Testing type of test_to_string: " << typeid(T).name() << std::endl; + using std::to_string; T x0{"23.43"}; BOOST_CHECK_EQUAL(to_string(x0), "23.430000"); @@ -433,7 +436,7 @@ int main() test_to_string(); test_round_trip(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); test_to_string(); test_round_trip(); diff --git a/test/test_fpclassify.cpp b/test/test_fpclassify.cpp index 10dadfe1..8ae41051 100644 --- a/test/test_fpclassify.cpp +++ b/test/test_fpclassify.cpp @@ -417,7 +417,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_log.cpp b/test/test_log.cpp index 309fe1e6..f747b78c 100644 --- a/test/test_log.cpp +++ b/test/test_log.cpp @@ -266,7 +266,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_numeric_limits.cpp b/test/test_numeric_limits.cpp index c8cc0f5f..e3482d1f 100644 --- a/test/test_numeric_limits.cpp +++ b/test/test_numeric_limits.cpp @@ -72,6 +72,7 @@ #ifdef BOOST_MSVC #pragma warning(disable : 4127) +#pragma warning(disable : 4723) #endif #define PRINT(x) \ @@ -269,7 +270,7 @@ void test() #ifdef TEST_CPP_DOUBLE_FLOAT -#if !(defined(_MSC_VER) && (_MSC_VER <= 1900)) +#if !(defined(BOOST_MSVC) && (BOOST_MSVC <= 1900)) template void test_constexpr_ness() { @@ -352,16 +353,16 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif - #if !(defined(_MSC_VER) && (_MSC_VER <= 1900)) + #if !(defined(BOOST_MSVC) && (BOOST_MSVC <= 1900)) test_constexpr_ness(); test_constexpr_ness(); test_constexpr_ness(); #endif - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test_constexpr_ness(); #endif #endif diff --git a/test/test_pow.cpp b/test/test_pow.cpp index d40b40e1..d7325020 100644 --- a/test/test_pow.cpp +++ b/test/test_pow.cpp @@ -40,50 +40,81 @@ #endif #if defined(TEST_MPF_50) -#include "test_pow_data.hpp" #include #endif #if defined(TEST_MPFR_50) -#include "test_pow_data.hpp" #include #endif #if defined(TEST_MPFI_50) -#include "test_pow_data.hpp" #include #endif #ifdef TEST_BACKEND -#include "test_pow_data.hpp" #include #endif #ifdef TEST_CPP_DEC_FLOAT -#include "test_pow_data.hpp" #include #endif #ifdef TEST_FLOAT128 -#include "test_pow_data.hpp" #include #endif #ifdef TEST_CPP_BIN_FLOAT -#include "test_pow_data.hpp" #include #endif #ifdef TEST_CPP_DOUBLE_FLOAT -#include "test_pow_data_df.hpp" #include #endif -#if defined(TEST_CPP_DOUBLE_FLOAT) -#include "test_pow_data_df.hpp" -#else #include "test_pow_data.hpp" -#endif +#include "test_pow_data_reduced.hpp" + + +namespace local { + + template + struct data_maker + { + static auto get_data() -> const DataArrayType& { static const DataArrayType instance { }; return instance; } + }; + + template <> + struct data_maker final + { + using local_array_type = test_pow_data::test_pow_data_array_type_reduced; + + static auto get_data() -> const local_array_type& + { + static const local_array_type instance { test_pow_data::data_reduced }; + + return instance; + } + }; + + template <> + struct data_maker final + { + using local_array_type = test_pow_data::test_pow_data_array_type_default; + + static auto get_data() -> const local_array_type& + { + static const local_array_type instance { test_pow_data::data }; + + return instance; + } + }; + +} // namespace local template void test() { std::cout << "Testing type: " << typeid(T).name() << std::endl; - static const test_pow_data::test_pow_data_array_type data { test_pow_data::data }; + using local_test_pow_data_array_type = + typename std::conditional<::has_poor_exp_range_or_precision_support::value, + test_pow_data::test_pow_data_array_type_reduced, + test_pow_data::test_pow_data_array_type_default>::type; + + const local_test_pow_data_array_type& data = local::data_maker::get_data(); unsigned max_err = 0; for (unsigned k = 0; k < data.size(); k++) @@ -192,19 +223,11 @@ int main() test, long long> > >(); #endif #ifdef TEST_CPP_DOUBLE_FLOAT - { - using boost::multiprecision::cpp_double_double; - using boost::multiprecision::cpp_double_long_double; - #if defined(BOOST_HAS_FLOAT128) - using boost::multiprecision::cpp_double_float128; - #endif - - test(); - test(); - #if defined(BOOST_HAS_FLOAT128) - test(); - #endif - } + test(); + test(); + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) + test(); + #endif #endif return boost::report_errors(); } diff --git a/test/test_pow_data.hpp b/test/test_pow_data.hpp index 3250f563..996681b7 100644 --- a/test/test_pow_data.hpp +++ b/test/test_pow_data.hpp @@ -19,9 +19,9 @@ namespace test_pow_data { - using test_pow_data_array_type = std::array, std::size_t { UINT32_C(702) }>; + using test_pow_data_array_type_default = std::array, std::size_t { UINT32_C(702) }>; - static const test_pow_data_array_type data = + static const test_pow_data_array_type_default data = {{ {{"9.85291419463953934609889984130859375e4", "8.4167086266170372255146503448486328125e2", "8.66781019918879108354226292713799369912745098619466567318041467361236175866573114777000418440761829061824953361563557580935951901405814080757565313129904800947783606850513184296612628910656615168927761935861462770335134108408073175949783551491164949747086136599355880600420490275164555515512645668845e4202"}}, {{"1.652914355109703592461301013827323913574218750e1", "4.936528947862250937816952500725165009498596191406250e-2", "1.14852190138491736562279120519668390081141778746743826681517181158751264571350304943298501284647564489716027476004029804110782430201351750715968215799574772058637701195873519618784612525011353325208230847515250406858209757415407239793739704829281917272032288615255140733409015874140869835291148547238"}}, diff --git a/test/test_pow_data_df.hpp b/test/test_pow_data_reduced.hpp similarity index 99% rename from test/test_pow_data_df.hpp rename to test/test_pow_data_reduced.hpp index 73b93e29..30c5eb7f 100644 --- a/test/test_pow_data_df.hpp +++ b/test/test_pow_data_reduced.hpp @@ -9,17 +9,17 @@ // "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations", // in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469 -#ifndef BOOST_MP_TEST_POW_DATA_DF_HPP - #define BOOST_MP_TEST_POW_DATA_DF_HPP +#ifndef BOOST_MP_TEST_POW_DATA_REDUCED_HPP + #define BOOST_MP_TEST_POW_DATA_REDUCED_HPP #include #include namespace test_pow_data { - using test_pow_data_array_type = std::array, std::size_t { UINT32_C(641) }>; + using test_pow_data_array_type_reduced = std::array, std::size_t { UINT32_C(641) }>; - static const test_pow_data_array_type data = + static const test_pow_data_array_type_reduced data_reduced = {{ {{"16.5291435510970359246130101382732391357421875", "0.0493652894786225093781695250072516500949859619140625", "1.148521901384917365622791205196683900811417787467438266815171811587512645713503049432985012846475645"}}, {{"0.272264614486854572561469467473216354846954345703125", "0.0004869544345559033600434606370299661648459732532501220703125", "0.9993666822419621463685898095771200117231983084504331852993667325006778736374601559705472670997199143"}}, @@ -666,4 +666,4 @@ } // namespace test_pow_data -#endif // BOOST_MP_TEST_POW_DATA_DF_HPP +#endif // BOOST_MP_TEST_POW_DATA_REDUCED_HPP diff --git a/test/test_round.cpp b/test/test_round.cpp index 7db20113..dc1c685d 100644 --- a/test/test_round.cpp +++ b/test/test_round.cpp @@ -175,6 +175,29 @@ void check_trunc_result(T a, U u) } } +namespace local { + +template +auto fail_gate_maker +{ + has_poor_exp_range_or_precision_support::value + ? + [](const T& my_sum, const T& my_a) -> bool + { + const T ratio { my_sum / my_a }; + const T delta { fabs(1 - ratio) }; + + return (delta > std::numeric_limits::epsilon()); + } + : + [](const T& my_sum, const T& my_a) -> bool + { + return (my_sum != my_a); + } +}; + +} // namespace local + template void check_modf_result(T a, T fract, U ipart) { @@ -182,17 +205,7 @@ void check_modf_result(T a, T fract, U ipart) const T sum { fract + ipart }; - #if defined(TEST_CPP_DOUBLE_FLOAT) - const T ratio { sum / a }; - - const T delta { fabs(1 - ratio) }; - #endif - - #if defined(TEST_CPP_DOUBLE_FLOAT) - if(delta > std::numeric_limits::epsilon()) - #else - if (sum != a) - #endif + if (local::fail_gate_maker(sum, a)) { BOOST_ERROR("Fractional and integer results do not add up to the original value"); std::cerr << "Values were: " << std::setprecision(35) << " " @@ -504,7 +517,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_sf_import_c99.cpp b/test/test_sf_import_c99.cpp index 9f0bd2b1..bfc3ce3e 100644 --- a/test/test_sf_import_c99.cpp +++ b/test/test_sf_import_c99.cpp @@ -84,7 +84,8 @@ #include #include -#include "test.hpp" + +#include #ifdef signbit #undef signbit @@ -206,6 +207,8 @@ void test_unordered(T a, U b) template void test() { + std::cout << "Testing type: " << typeid(T).name() << std::endl; + // // Basic sanity checks for C99 functions which are just imported versions // from Boost.Math. These should still be found via ADL so no using declarations here... @@ -349,11 +352,8 @@ void test() s = 8 * std::numeric_limits::epsilon(); val = 2.5; { - #if defined(TEST_CPP_DOUBLE_FLOAT) - const auto my_s = s * 3; - #else - const auto my_s = s; - #endif + const T my_s { ::has_poor_exp_range_or_precision_support::value ? s * 3 : s }; + BOOST_CHECK_CLOSE_FRACTION(asinh(val), T("1.6472311463710957106248586104436196635044144301932365282203100930843983757633104078778420255069424907777006132075516484778755360595913172299093829522950397895699619540523579875476513967578478619028438291006578604823887119907434"), my_s); BOOST_CHECK_CLOSE_FRACTION(asinh(val + T(0)), T("1.6472311463710957106248586104436196635044144301932365282203100930843983757633104078778420255069424907777006132075516484778755360595913172299093829522950397895699619540523579875476513967578478619028438291006578604823887119907434"), my_s); } @@ -361,11 +361,8 @@ void test() BOOST_CHECK_CLOSE_FRACTION(acosh(val + T(0)), T("1.5667992369724110786640568625804834938620823510926588639329459980122148134693922696279968499622201141051039184050936311066453565386393240356562374302417843319480223211857615778787272615171906055455922537080327062362258846337050"), s); val = 0.5; { - #if defined(TEST_CPP_DOUBLE_FLOAT) - const auto my_s = s * 2; - #else - const auto my_s = s; - #endif + const T my_s { ::has_poor_exp_range_or_precision_support::value ? s * 2 : s }; + BOOST_CHECK_CLOSE_FRACTION(atanh(val), T("0.5493061443340548456976226184612628523237452789113747258673471668187471466093044834368078774068660443939850145329789328711840021129652599105264009353836387053015813845916906835896868494221804799518712851583979557605727959588753"), my_s); BOOST_CHECK_CLOSE_FRACTION(atanh(val + T(0)), T("0.5493061443340548456976226184612628523237452789113747258673471668187471466093044834368078774068660443939850145329789328711840021129652599105264009353836387053015813845916906835896868494221804799518712851583979557605727959588753"), my_s); } @@ -2298,7 +2295,7 @@ int main() #ifdef TEST_CPP_DOUBLE_FLOAT test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_sin.cpp b/test/test_sin.cpp index 3299c4b8..92b9c83f 100644 --- a/test/test_sin.cpp +++ b/test/test_sin.cpp @@ -391,7 +391,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_sinh.cpp b/test/test_sinh.cpp index fe747581..c375226a 100644 --- a/test/test_sinh.cpp +++ b/test/test_sinh.cpp @@ -263,7 +263,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_sqrt.cpp b/test/test_sqrt.cpp index 88c09adb..4750e67e 100644 --- a/test/test_sqrt.cpp +++ b/test/test_sqrt.cpp @@ -236,7 +236,7 @@ int main() test > >(); #endif #endif -#if defined(TEST_FLOAT128) && !defined(TEST_CPP_DOUBLE_FLOAT) +#if defined(TEST_FLOAT128) test(); #endif #ifdef TEST_CPP_BIN_FLOAT @@ -247,7 +247,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_tan.cpp b/test/test_tan.cpp index cb293c66..be83f16a 100644 --- a/test/test_tan.cpp +++ b/test/test_tan.cpp @@ -665,7 +665,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif diff --git a/test/test_tanh.cpp b/test/test_tanh.cpp index ba0edbc3..c80c2cd4 100644 --- a/test/test_tanh.cpp +++ b/test/test_tanh.cpp @@ -179,7 +179,7 @@ int main() test(); test(); test(); - #if defined(BOOST_HAS_FLOAT128) + #if defined(BOOST_MP_CPP_DOUBLE_FP_HAS_FLOAT128) test(); #endif #endif