E.V.E  0.1-beta

◆ lcm

eve::lcm = {}
inlineconstexpr

Callable object computing least common multiple.

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

Members Functions

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

template< value T, value U > auto operator()( T p, U n ) const noexcept requires compatible< T, U >;

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 least common multiple is defined only if p and n element are flint. If it is not the case the corresponding result will be Nan.

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

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

Parameters

cond : conditional expression

Return value

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


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(lcm)(a,b) is equivalent to lcm)(deco(round)(a),deco(round)(b)), but optimized when possible.

where deco is one of: to_nearest, downward, upward or toward_zero.


Type conversion

If the input types are integral, the result is succeptible to overflow, but will never be greater than the product of the two input values which will be representable in the upgraded integral type:

The call upgrade(lcm)(a,b) will then return a correct result in the upgraded type (see example below).

Example

See it live on Compiler Explorer

#include <eve/function/lcm.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
w_t pi8 = {93, -25, 32, 37}, qi8 = {42, 10, 27, 102};
w32_t pi32 = {93, -25, 32, 37}, qi32 = {42, 10, 27, 102};
std::cout << "---- simd" << '\n'
<< " <- pi8 = " << pi8 << '\n'
<< " <- qi8 = " << qi8 << '\n'
<< " -> lcm(pi8, qi8) = " << eve::lcm(pi8, qi8) << '\n'
<< " -> upgrade_(lcm)(pi8, qi8)) = " << eve::upgrade_(eve::lcm)(pi8, qi8) << '\n'
<< " -> lcm(pi32, qi32) = " << eve::lcm(pi32, qi32) << '\n';
std::uint32_t xi = 18, yi = 60;
std::cout << "---- scalar" << '\n'
<< " xi = " << xi << '\n'
<< " yi = " << yi << '\n'
<< " -> lcm(xi, yi) = " << eve::lcm(xi, yi) << '\n';
return 0;
}
constexpr callable_lcm_ lcm
Callable object computing least common multiple.
Definition: lcm.hpp:96
constexpr upgrade_converter const upgrade_
convert a eve::real_value to a eve::real_value of the upgraded base type.
Definition: converter.hpp:460
Wrapper for SIMD registers.
Definition: wide.hpp:65