E.V.E  0.1-beta

◆ fibonacci

eve::fibonacci = {}
inlineconstexpr

Callable object computing the nth value of the fibonacci sequence.

Required header: #include <eve/function/fibonacci.hpp>

Members Functions

Member Effect
operator() the nth value of the fibonacci sequence
operator[] Construct a conditional version of current function object

template< floating_value T, floating_value U, unsigned_value N > auto operator()( T x, U y, N n ) const noexcept requires compatible< T, U >;

Parameters

x, y: floating values.

n: unsigned value.

Return value

The result type is the common compatible type of the two first parameters, vectorized with the cardinality of the third one if necessary.

The recurrence formula defining the fibonacci sequence is:

 - r(0) = x
 - r(1) = y
 - r(i+2) = r(i+1)+r(i),  i > 2

The function return elementwise r(n), but the result is computed using the Binet formula.


auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::fibonacci

Parameters

cond : conditional expression

Return value

A Callable object so that the expression fibonacci[cond](x, ...) is equivalent to if_else(cond,fibonacci(x, ...),x)


Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/fibonacci.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;
}
constexpr callable_fibonacci_ fibonacci
Callable object computing the nth value of the fibonacci sequence.
Definition: fibonacci.hpp:83
Wrapper for SIMD registers.
Definition: wide.hpp:65