E.V.E  0.1-beta

◆ nth_prime

eve::nth_prime = {}
inlineconstexpr

Callable object performing the computation the nth prime integer.

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

Members Functions

Member Effect
operator() unsigned integral nth_prime

template< unsigned_value T > auto operator()( T n ) const noexcept;

Parameters

n: unsigned value.

Return value

The result element type is the same as the input one unless a converter is applied to nth_prime. See the example below.

Almost no computations are made, the results are from a lookup table.

2 is the first prime number (n=0). If the output is of integral type incorrect computation will return 0, but if the result has been converted to a floating value (by concerting the object function) incorrect computation will return nan

Warning
this function will return 0 (or nan) as soon as the correct result will not be exactly represented in the output type or (for the current implementation) if n is greater or equal to 10000.

Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/nth_prime.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) << '\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 callable_nth_prime_ nth_prime
Callable object performing the computation the nth prime integer.
Definition: nth_prime.hpp:70
constexpr converter_type< std::uint32_t > const uint32
convert a eve::real_value to a uint32 based eve::integral_real_value.
Definition: converter.hpp:229
constexpr converter_type< float > const float32
convert a eve::real_value to a float32 based eve::floating_real_value.
Definition: converter.hpp:133
Wrapper for SIMD registers.
Definition: wide.hpp:65