E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ gcd

auto eve::gcd = functor<gcd_t>
inlineconstexpr

Header file

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
// Regular overload
template <value T0, value T1> constexpr common_value_t<T0, T1> gcd(T0 p, T1 n) noexcept; // 1
// Lanes masking
constexpr auto gcd[conditional_expr auto c](value auto p, value auto n) noexcept; // 2
constexpr auto gcd[logical_value auto m](value auto p, value auto n) noexcept; // 2
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:132
The concept value<T> is satisfied if and only if T satisfies either eve::scalar_value or eve::simd_va...
Definition value.hpp:34
constexpr auto gcd
elementwise_callable object computing the greatest common divisor of the inputs.
Definition gcd.hpp:79
EVE Main Namespace.
Definition abi.hpp:18
typename eve::detail::common_value_impl< void, Ts... >::type common_value_t
Computes the SIMD-compatible common type between all Ts.
Definition common_value.hpp:69

Parameters

Return value

  1. If both p and n are zero, returns zero. Otherwise, returns the greatest common divisor of |p| and |n|.
  2. The operation is performed conditionnaly.
Warning
p and n can be of any values type, but when the types are not integral the greatest common divisor is defined only if p and n elements are flint. If any of the arguments is not flint the result is undefined.

External references

Example

// revision 1
#include <eve/module/combinatorial.hpp>
#include <iostream>
eve::wide<float> wf0([](auto i, auto c)->float{ return (i-c/2);});
eve::wide<float> wf1([](auto i, auto )->float{ return 10*i; });
eve::wide n{93, 25, 32, 368, 216, 43, 18, 25};
eve::wide p{42, 30, 27, 1024, 36, 12, 51, 44};
int main(){
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- n = " << n << "\n";
std::cout << "<- p = " << p << "\n";
std::cout << "-> gcd(wf0, wf1) = " << eve::gcd(wf0, wf1) << "\n";
std::cout << "-> gcd[ignore_last(2)](wf0, wf1)= " << eve::gcd[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> gcd[wf0 != -2.0f](wf0, wf1) = " << eve::gcd[wf0 != -2.0f](wf0, wf1) << "\n";
std::cout << "-> gcd(p, n) = " << eve::gcd(p, n) << "\n";
}
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:332
Wrapper for SIMD registers.
Definition wide.hpp:86