2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00
Files
math/example/reciprocal_fibonacci_constant.cpp
Madhur Chauhan 68d6a75f7c Fibonacci numbers (#376)
* Fibonacci: Initial commit. Working.

* Fibonacci: Address Nick's comments. Added unchecked factorial.

* Fibonacci: Improved overflow testing

* Fibonacci: Added unit tests

* Fibonacci: Performance report

* Fibonacci: Nick's comments - Complexity

* Fibonacci: Add UT to Jamfile

* Make Fibonacci and UT C++03 friendly.

Add UT to Jamfile.

* Fibonacci: Remove GMP dependency

* 1. Added fibonacci generator with unit tests
2. Added example of reciprocal fibonacci constant

* [CI SKIP] Fibonacci: First cut at documentation

* Fibonacci: Finishing up changes [CI SKIP]

* Fibonacci: Removing unnecessary html files

* fibonacci: rename to unchecked_fibonacci

* fibonacci: remove documentation

Co-authored-by: Created by Ansible <madhur@dev-sng-build1.kdev>
2021-03-16 09:11:10 -04:00

27 lines
939 B
C++

// Copyright 2020, Madhur Chauhan
// 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)
// This is an example to calculate Reciprocal Fibonacci Constant (A079586 in the OEIS)
// compile with flags: -std=c++11 -lmpfr
#include <boost/math/special_functions/fibonacci.hpp>
#include <boost/multiprecision/mpfr.hpp>
#include <iomanip>
#include <iostream>
int main() {
using Real = boost::multiprecision::mpfr_float_1000;
boost::math::fibonacci_generator<Real> gen;
gen.set(1); // start producing values from 1st fibonacci number
Real ans = 0;
const int ITR = 1000;
for (int i = 0; i < ITR; ++i) {
ans += 1.0 / gen();
}
std::cout << std::setprecision(1000) << "Reciprocal fibonacci constant after "
<< ITR << " iterations is: " << ans << std::endl;
}