123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #ifndef BOOST_MATH_TOOLS_COHEN_ACCELERATION_HPP
- #define BOOST_MATH_TOOLS_COHEN_ACCELERATION_HPP
- #include <limits>
- #include <cmath>
- #include <cstdint>
- namespace boost::math::tools {
- template<class G>
- auto cohen_acceleration(G& generator, std::int64_t n = -1)
- {
- using Real = decltype(generator());
-
-
- using std::log;
- using std::pow;
- using std::ceil;
- using std::sqrt;
- auto n_ = static_cast<Real>(n);
- if (n < 0)
- {
-
-
- n_ = static_cast<Real>(ceil(log(Real(4)/std::numeric_limits<Real>::epsilon())*Real(0.5672963285532555)));
- n = static_cast<std::int64_t>(n_);
- }
-
- auto d = static_cast<Real>(pow(Real(3 + sqrt(Real(8))), n_));
- d = (d + Real(1)/d)/2;
- Real b = -1;
- Real c = -d;
- Real s = 0;
- for (Real k = 0; k < n_; ++k) {
- c = b - c;
- s += c*generator();
- b = (k+n_)*(k-n_)*b/((k+Real(1)/Real(2))*(k+1));
- }
- return s/d;
- }
- }
- #endif
|