]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/example/to_continued_fraction.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / math / example / to_continued_fraction.cpp
CommitLineData
20effc67
TL
1// (C) Copyright Nick Thompson 2020.
2// Use, modification and distribution are subject to the
3// Boost Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5#include <iostream>
6#include <boost/math/constants/constants.hpp>
7#include <boost/math/tools/simple_continued_fraction.hpp>
8#include <boost/multiprecision/cpp_bin_float.hpp>
9
10using boost::math::constants::root_two;
11using boost::math::constants::phi;
12using boost::math::constants::pi;
13using boost::math::constants::e;
14using boost::math::constants::zeta_three;
15using boost::math::tools::simple_continued_fraction;
16
17int main()
18{
19 using Real = boost::multiprecision::cpp_bin_float_100;
20 auto phi_cfrac = simple_continued_fraction(phi<Real>());
21 std::cout << "φ ≈ " << phi_cfrac << "\n\n";
22
23 auto pi_cfrac = simple_continued_fraction(pi<Real>());
24 std::cout << "π ≈ " << pi_cfrac << "\n";
25 std::cout << "Known: [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, 1, 84, 2, 1, 1, 15, 3, 13, 1, 4, 2, 6, 6, 99, 1, 2, 2, 6, 3, 5, 1, 1, 6, 8, 1, 7, 1, 2, 3, 7, 1, 2, 1, 1, 12, 1, 1, 1, 3, 1, 1, 8, 1, 1, 2, 1, 6, 1, 1, 5, 2, 2, 3, 1, 2, 4, 4, 16, 1, 161, 45, 1, 22, 1, 2, 2, 1, 4, 1, 2, 24, 1, 2, 1, 3, 1, 2, 1, ...]\n\n";
26
27 auto rt_cfrac = simple_continued_fraction(root_two<Real>());
28 std::cout << "√2 ≈ " << rt_cfrac << "\n\n";
29
30 auto e_cfrac = simple_continued_fraction(e<Real>());
31 std::cout << "e ≈ " << e_cfrac << "\n";
32
33 // Correctness can be checked in Mathematica via: ContinuedFraction[Zeta[3], 500]
34 auto z_cfrac = simple_continued_fraction(zeta_three<Real>());
35 std::cout << "ζ(3) ≈ " << z_cfrac << "\n";
36}