E.V.E
v2022.03.00

◆ nth_prime

eve::nth_prime = {}
inlineconstexpr

Returns the nth prime number.

Defined in Header

#include <eve/module/combinatorial.hpp>

Callable Signatures

namespace eve
{
template< eve::unsigned_value N >
eve::as_wide_as< double, N > nth_prime(N n) noexcept;
}
constexpr callable_nth_prime_ nth_prime
Returns the nth prime number.
Definition: nth_prime.hpp:77
Definition: all_of.hpp:22

Parameters

  • n : unsigned argument. If n is greater than 10'000, behavior is undefined.

Return value

The value of the nth prime number is returned.

Notes

  • 2 is the first prime. It is returned for n=0.
  • Almost no computations are made, the results are from a lookup table. The result element type is the same as the input one unless a converter is applied to eve::nth_prime (see below).

Example

#include <eve/module/combinatorial.hpp>
#include <eve/wide.hpp>
#include <iostream>
int
main()
{
w16_t pi16 = {52, 53, 6541, 6542, 0, 1, 999, 10000};
std::cout << "---- simd" << '\n'
<< " <- pi16 = " << pi16 << '\n'
<< " -> nth_prime(pi16) = " << eve::nth_prime(pi16)
<< " // note the 0 outputs meaning overflow or out of range\n";
std::uint16_t xi = 18;
std::cout << "---- scalar" << '\n'
<< " xi = " << xi << '\n'
<< " -> nth_prime(xi) = " << eve::nth_prime(xi) << '\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 not to be representable in the input type. A converter can be applied to choose the output type and get the correct result.

    Example

    #include <eve/module/combinatorial.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int
    main()
    {
    w16_t pi16 = {52, 53, 6541, 6542, 0, 1, 999, 10000};
    std::cout << "---- simd" << '\n'
    << " <- pi16 = " << pi16 << '\n'
    << " -> uint32(nth_prime)(pi16) = " << eve::uint32(eve::nth_prime)(pi16) << '\n'
    << " -> float32(nth_prime)(pi16) = " << eve::float32(eve::nth_prime)(pi16) << '\n'
    << " -> float32(nth_prime(pi16)) = " << eve::float32(eve::nth_prime(pi16))
    << "// mind the parentheses\n\n";
    std::uint16_t xi = 18;
    std::cout << "---- scalar" << '\n'
    << " xi = " << xi << '\n'
    << " -> nth_prime(xi) = " << eve::nth_prime(xi) << '\n';
    return 0;
    }
    constexpr converter_type< std::uint32_t > const uint32
    convert a eve::value to a std::uint32_t based eve::value.
    Definition: converter.hpp:313
    constexpr converter_type< float > const float32
    convert a eve::value to a float32 based eve::floating_value.
    Definition: converter.hpp:130