/* * Copyright Nick Thompson, 2020 * Use, modification and distribution are subject to 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 "math_unit_test.hpp" #include #include #ifdef BOOST_HAS_FLOAT128 #include using boost::multiprecision::float128; #endif #include #include #if __has_include() # include #endif using boost::math::tools::cohen_acceleration; using boost::multiprecision::cpp_bin_float_100; using boost::math::constants::pi; using std::log; template class G { public: G(){ k_ = 0; } Real operator()() { k_ += 1; return 1/(k_*k_); } private: Real k_; }; template void test_pisq_div12() { auto g = G(); Real x = cohen_acceleration(g); CHECK_ULP_CLOSE(pi()*pi()/12, x, 3); } template class Divergent { public: Divergent(){ k_ = 0; } // See C3 of: https://people.mpim-bonn.mpg.de/zagier/files/exp-math-9/fulltext.pdf Real operator()() { using std::log; k_ += 1; return log(k_); } private: Real k_; }; template void test_divergent() { auto g = Divergent(); Real x = -cohen_acceleration(g); CHECK_ULP_CLOSE(log(pi()/2)/2, x, (std::numeric_limits::digits > 100 ? 350 : 150)); } int main() { #ifdef __STDCPP_FLOAT32_T__ test_pisq_div12(); test_divergent(); #else test_pisq_div12(); test_divergent(); #endif #ifdef __STDCPP_FLOAT64_T__ test_pisq_div12(); test_divergent(); #else test_divergent(); test_pisq_div12(); #endif test_divergent(); test_pisq_div12(); #ifdef BOOST_HAS_FLOAT128 test_pisq_div12(); test_divergent(); #endif return boost::math::test::report_errors(); }