E.V.E  0.1-beta

◆ gcd

eve::gcd = {}
inlineconstexpr

Callable object computing greater common divisor.

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

Members Functions

Member Effect
operator() greater common divisor operation
operator[] Construct a conditional version of current function object

auto operator()( real_value p, real_value n ) const noexcept;
Definition: value.hpp:93

Parameters

p, n: real values.

Return value

The result type is the common compatible type of the two parameters.

Warning
p and n can be of any real values type, but when the types are not integral the greatest common divisor is defined only if p and n element are flint. If it is not the case the corresponding result will be Nan.

Supported decorators

If the user calls the function with floating parameters, he can enforce the fact that all parameters are flint using one of the roundings decorators on the object function. Namely:

deco(gcd)(a,b) is equivalent to gcd(deco(round)(a),deco(round)(b))

but the computation is optimized when possible

deco can be one of: to_nearest, downward, upward or toward_zero.


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

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

Parameters

cond : conditional expression

Return value

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

Example

See it live on Compiler Explorer

#include <eve/function/gcd.hpp>
#include <eve/literals.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
w_t pi = {93, -25, 32, 368}, qi = {42, 30, 27, 1024};
std::cout << "---- simd" << '\n'
<< " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
<< " -> gcd(pi, qi) = " << eve::gcd(pi, qi) << '\n';
std::uint32_t xi = 18, yi = 60;
std::cout << "---- scalar" << '\n'
<< " xi = " << xi << '\n'
<< " yi = " << yi << '\n'
<< " -> gcd(xi, yi) = " << eve::gcd(xi, yi) << '\n';
return 0;
}
constexpr callable_gcd_ gcd
Callable object computing greater common divisor.
Definition: gcd.hpp:82
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
Wrapper for SIMD registers.
Definition: wide.hpp:65