E.V.E
v2022.09.01

◆ lcm

eve::lcm = {}
inlineconstexpr

Computes the least common multiple of the inputs.

Defined in Header

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
template< eve::real_value T, eve::real_value U >
T lcm(T p, U n) noexcept;
}
constexpr callable_lcm_ lcm
Computes the least common multiple of the inputs.
Definition: lcm.hpp:75
Definition: all_of.hpp:22

Parameters

p, n: real arguments.

Return value

Returns the least common multiple of |p| and |n|.

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 elements are [flint](eve::is_flint). If any of the arguments is not flint the result is undefined.

Example

#include <eve/module/combinatorial.hpp>
#include <eve/wide.hpp>
#include <iostream>
int
main()
{
w32_t pi32 = {93, 25, 32, 37}, qi32 = {42, 10, 27, 102};
std::cout << "---- simd" << '\n'
<< " <- pi32 = " << pi32 << '\n'
<< " <- qi32 = " << qi32 << '\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;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Optimized Conversion Call If the input types are integral, the result is susceptible 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) returns a correct result in the upgraded type if the upgraded type is available.

    Example

    #include <eve/module/combinatorial.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int
    main()
    {
    w_t pi8 = {93, 25, 32, 37}, qi8 = {42, 10, 27, 102};
    std::cout << "---- simd" << '\n'
    << " <- pi8 = " << pi8 << '\n'
    << " <- qi8 = " << qi8 << '\n'
    << " -> lcm(pi8, qi8) = " << eve::lcm(pi8, qi8)
    << "// incorrect due to overflow\n"
    << " -> upgrade_(lcm)(pi8, qi8)) = " << eve::upgrade_(eve::lcm)(pi8, qi8) << '\n';
    return 0;
    }
    constexpr upgrade_converter const upgrade_
    convert a eve::value to the upgraded base type.
    Definition: converter.hpp:740