E.V.E
v2022.09.01

◆ fibonacci

eve::fibonacci = {}
inlineconstexpr

Computes the nth element of the Fibonacci sequence \((f_i)_{i\in \mathbb{N}}\).

The sequence is defined by the recurrence relations :

  • \(f_0 = x\)
  • \(f_1 = y\)
  • \(f_{n+2} = f_{n+1} + f_{n}, n > 0\)

but is computed using the Binet formula.

Defined in header

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
template< eve::unsigned_value N, eve::floating_real_value T, eve::floating_real_value U>
requires eve::compatible<T, U>
eve::common_compatible_t<T, U> fibonacci(N n, T x, U y) noexcept
}
constexpr callable_fibonacci_ fibonacci
Computes the nth element of the Fibonacci sequence .
Definition: fibonacci.hpp:61
Definition: all_of.hpp:22

Parameters

n: index of the value to be returned

x, y: floating point arguments : \(f_0\) and \(f_1\).

Return value

The value of the nth element of the Fibonacci sequence beginning by x and y is returned.

Example

#include <eve/module/combinatorial.hpp>
#include <eve/wide.hpp>
#include <iomanip>
#include <iostream>
int
main()
{
w32_t n = {13, 25, 32, 180, 1, 2, 3, 4};
wf32_t a = {1, 2, 3, 4, 0.5, 0.33, -4.5, 0};
wf32_t b = {2, 3, 4, 0.5, 0.33, -4.5, 0, 1};
std::cout << "---- simd" << '\n'
<< " <- n = " << n << '\n'
<< " <- a = " << a << '\n'
<< " <- b = " << b << '\n'
<< " -> fibonacci(n, a, b) = " << eve::fibonacci(n, a, b) << '\n'
<< " -> fibonacci(4u, a, b) = " << eve::fibonacci(4u, a, b) << '\n'
<< " -> fibonacci(n, 1.0f, 3.0f) = " << eve::fibonacci(n, 1.0f, 3.0f) << '\n'
<< " -> fibonacci(n, 1.0f, b) = " << eve::fibonacci(n, 1.0f, b) << '\n';
std::uint32_t ns = 10;
float as = 1;
float bs = 1;
std::cout << "---- scalar" << '\n'
<< " ns = " << ns << '\n'
<< " as = " << as << '\n'
<< " bs = " << bs << '\n'
<< " -> fibonacci(ns, as, bs) = " << eve::fibonacci(ns, as, bs) << '\n';
return 0;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65