/////////////////////////////////////////////////////////////// // Copyright Christopher Kormanyos 2002 - 2011. // Copyright 2011 John Maddock. 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 #include "test.hpp" #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 template void test() { typedef boost::multiprecision::number > mpfr_float_1000; for (int n = -20; n <= 20; ++n) { std::cout << "Testing n = " << n << std::endl; T boundary = boost::math::constants::half_pi() * n; T val = boundary; for (unsigned i = 0; i < 200; ++i) { mpfr_float_1000 comparison(val); comparison = cos(comparison); T found = cos(val); T expected = T(comparison); BOOST_CHECK_LE(boost::math::epsilon_difference(found, expected), 20); //std::cout << std::setprecision(10) << val << std::endl; //std::cout << std::setprecision(50) << found << std::endl; //std::cout << std::setprecision(50) << comparison << std::endl; //std::cout << std::setprecision(50) << expected << std::endl; 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 = cos(comparison); T found = cos(val); T expected = T(comparison); BOOST_CHECK_LE(boost::math::epsilon_difference(found, expected), 20); } } } 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(); }