]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/cohen_acceleration_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / math / test / cohen_acceleration_test.cpp
1 /*
2 * Copyright Nick Thompson, 2020
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 */
7
8 #include "math_unit_test.hpp"
9 #include <boost/math/tools/cohen_acceleration.hpp>
10 #include <boost/math/constants/constants.hpp>
11 #ifdef BOOST_HAS_FLOAT128
12 #include <boost/multiprecision/float128.hpp>
13 using boost::multiprecision::float128;
14 #endif
15 #include <boost/multiprecision/cpp_bin_float.hpp>
16 #include <cmath>
17
18 using boost::math::tools::cohen_acceleration;
19 using boost::multiprecision::cpp_bin_float_100;
20 using boost::math::constants::pi;
21 using std::log;
22
23 template<typename Real>
24 class G {
25 public:
26 G(){
27 k_ = 0;
28 }
29
30 Real operator()() {
31 k_ += 1;
32 return 1/(k_*k_);
33 }
34
35 private:
36 Real k_;
37 };
38
39 template<typename Real>
40 void test_pisq_div12()
41 {
42 auto g = G<Real>();
43 Real x = cohen_acceleration(g);
44 CHECK_ULP_CLOSE(pi<Real>()*pi<Real>()/12, x, 3);
45 }
46
47 template<typename Real>
48 class Divergent {
49 public:
50 Divergent(){
51 k_ = 0;
52 }
53
54 // See C3 of: https://people.mpim-bonn.mpg.de/zagier/files/exp-math-9/fulltext.pdf
55 Real operator()() {
56 using std::log;
57 k_ += 1;
58 return log(k_);
59 }
60
61 private:
62 Real k_;
63 };
64
65 template<typename Real>
66 void test_divergent()
67 {
68 auto g = Divergent<Real>();
69 Real x = -cohen_acceleration(g);
70 CHECK_ULP_CLOSE(log(pi<Real>()/2)/2, x, 135);
71 }
72
73 int main()
74 {
75 test_pisq_div12<float>();
76 test_pisq_div12<double>();
77 test_pisq_div12<long double>();
78
79 test_divergent<float>();
80 test_divergent<double>();
81 test_divergent<long double>();
82
83 #ifdef BOOST_HAS_FLOAT128
84 test_pisq_div12<float128>();
85 test_divergent<float128>();
86 #endif
87 return boost::math::test::report_errors();
88 }