|
1 | 1 | // (C) Copyright Nick Thompson 2020.
|
| 2 | +// (C) Copyright Matt Borland 2023. |
2 | 3 | // Use, modification and distribution are subject to the
|
3 | 4 | // Boost Software License, Version 1.0. (See accompanying file
|
4 | 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
14 | 15 | #include <limits>
|
15 | 16 | #include <stdexcept>
|
16 | 17 | #include <sstream>
|
| 18 | +#include <utility> |
| 19 | +#include <cstdint> |
17 | 20 |
|
18 | 21 | #include <boost/math/tools/is_standalone.hpp>
|
19 | 22 | #ifndef BOOST_MATH_STANDALONE
|
20 | 23 | #include <boost/config.hpp>
|
21 | 24 | #ifdef BOOST_NO_CXX17_IF_CONSTEXPR
|
22 |
| -#error "The header <boost/math/norms.hpp> can only be used in C++17 and later." |
| 25 | +#error "The header <boost/math/simple_continued_fraction.hpp> can only be used in C++17 and later." |
23 | 26 | #endif
|
24 | 27 | #endif
|
25 | 28 |
|
@@ -108,7 +111,7 @@ class simple_continued_fraction {
|
108 | 111 | // Precompute the most probable logarithms. See the Gauss-Kuzmin distribution for details.
|
109 | 112 | // Example: b_i = 1 has probability -log_2(3/4) ~ .415:
|
110 | 113 | // A random partial denominator has ~80% chance of being in this table:
|
111 |
| - const std::array<Real, 7> logs{std::numeric_limits<Real>::quiet_NaN(), Real(0), log(static_cast<Real>(2)), log(static_cast<Real>(3)), log(static_cast<Real>(4)), log(static_cast<Real>(5)), log(static_cast<Real>(6))}; |
| 114 | + const std::array<Real, 7> logs{std::numeric_limits<Real>::quiet_NaN(), static_cast<Real>(0), log(static_cast<Real>(2)), log(static_cast<Real>(3)), log(static_cast<Real>(4)), log(static_cast<Real>(5)), log(static_cast<Real>(6))}; |
112 | 115 | Real log_prod = 0;
|
113 | 116 | for (size_t i = 1; i < b_.size(); ++i) {
|
114 | 117 | if (b_[i] < static_cast<Z>(logs.size())) {
|
@@ -138,6 +141,11 @@ class simple_continued_fraction {
|
138 | 141 | const std::vector<Z>& partial_denominators() const {
|
139 | 142 | return b_;
|
140 | 143 | }
|
| 144 | + |
| 145 | + inline std::vector<Z>&& get_data() noexcept |
| 146 | + { |
| 147 | + return std::move(b_); |
| 148 | + } |
141 | 149 |
|
142 | 150 | template<typename T, typename Z2>
|
143 | 151 | friend std::ostream& operator<<(std::ostream& out, simple_continued_fraction<T, Z2>& scf);
|
@@ -171,6 +179,12 @@ std::ostream& operator<<(std::ostream& out, simple_continued_fraction<Real, Z2>&
|
171 | 179 | return out;
|
172 | 180 | }
|
173 | 181 |
|
| 182 | +template<typename Real, typename Z = std::int64_t> |
| 183 | +inline auto simple_continued_fraction_coefficients(Real x) |
| 184 | +{ |
| 185 | + auto temp = simple_continued_fraction(x); |
| 186 | + return temp.get_data(); |
| 187 | +} |
174 | 188 |
|
175 | 189 | }
|
176 | 190 | #endif
|
0 commit comments