/////////////////////////////////////////////////////////////// // Copyright 2011 - 2025 John Maddock. // Copyright Christopher Kormanyos 2002 - 2025. // 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 // // This work is based on an earlier work: // "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 #ifdef _MSC_VER #define _SCL_SECURE_NO_WARNINGS #endif #include #include #include #if !defined(TEST_MPF_50) && !defined(TEST_MPF) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_FLOAT128) && !defined(TEST_CPP_BIN_FLOAT) && !defined(TEST_MPFR_50) #define TEST_MPF_50 #define TEST_CPP_DEC_FLOAT #define TEST_FLOAT128 #define TEST_CPP_BIN_FLOAT #define TEST_MPFR_50 #ifdef _MSC_VER #pragma message("CAUTION!!: No backend type specified so testing everything.... this will take some time!!") #endif #ifdef __GNUC__ #pragma warning "CAUTION!!: No backend type specified so testing everything.... this will take some time!!" #endif #endif #include #if defined(TEST_MPF_50) #include #endif #ifdef TEST_CPP_DEC_FLOAT #include #endif #ifdef TEST_FLOAT128 #include #endif #ifdef TEST_CPP_BIN_FLOAT #include #endif #include template void test() { std::cout << "Testing type: " << typeid(T).name() << std::endl; std::cout << "Round: n="; for (int n = 0; n <= 20; ++n) { if (n != 0) std::cout << ","; std::cout << n; using mpfr_float_1000 = boost::multiprecision::number>; T boundary = boost::math::constants::half_pi() * n; T val = boundary; if((n == 0) && ((std::numeric_limits::min_exponent <= std::numeric_limits::min_exponent) || (!std::numeric_limits::is_specialized))) continue; for (unsigned i = 0; i < 200; ++i) { mpfr_float_1000 comparison(val); comparison = sin(comparison); T found = sin(val); T expected = T(comparison); BOOST_CHECK_LE(boost::math::epsilon_difference(found, expected), 20); val = boost::math::float_next(val); } val = boundary; for (unsigned i = 0; i < 200; ++i) { val = boost::math::float_prior(val); mpfr_float_1000 comparison(val); comparison = sin(comparison); T found = sin(val); T expected = T(comparison); BOOST_CHECK_LE(boost::math::epsilon_difference(found, expected), 20); } } std::cout << std::endl; } int main() { #ifdef TEST_MPF_50 test(); test(); boost::multiprecision::mpf_float::default_precision(50); test(); boost::multiprecision::mpf_float::default_precision(100); test(); #endif #ifdef TEST_MPFR_50 boost::multiprecision::mpfr_float::default_precision(50); test(); boost::multiprecision::mpfr_float::default_precision(100); test(); #endif #ifdef TEST_CPP_DEC_FLOAT test(); test(); #ifndef SLOW_COMPLER // Some "peculiar" digit counts which stress our code: test > >(); test > >(); test > >(); test > >(); test > >(); test > >(); test > > >(); test > > >(); // Check low multiprecision digit counts. test > >(); test > >(); #endif #endif #ifdef TEST_FLOAT128 test(); #endif #ifdef TEST_CPP_BIN_FLOAT test(); test(); test, long long> > >(); #endif return boost::report_errors(); }