E.V.E
v2023.02.15

◆ nearest

eve::nearest = {}
inlineconstexpr

Computes the nearest integer to the input.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
T nearest(T x) noexcept;
}
constexpr callable_nearest_ nearest
Computes the nearest integer to the input.
Definition: nearest.hpp:69
Definition: abi.hpp:18

Parameters

Return value

Computes elementwise the integer nearest to x.

If x is an exact half-integer the rounding is made to the nearest even integer.

The standard proposes 4 rounding modes namely: FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO. This function object implements the FE_TONEAREST version.

For complex inputs the nearest operation is applied to both real and imaginary parts.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_ft pf = {-1.0f, -1.3f, -1.5f, -1.7f, 2.0f, 2.3f, 2.5f, 2.7f};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> nearest(pf) = " << eve::nearest(pf) << '\n';
float xf = -32.768f;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> nearest(xf) = " << eve::nearest(xf) << '\n';
return 0;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve;nearest[mask](x) provides a masked version of eve::nearest which is equivalent to if_else (mask, nearest(x), x).

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft pf = {-1.0f, -1.3f, -1.5f, -1.7f, 2.0f, 2.3f, 2.5f, 2.7f};
    std::cout << "---- simd" << '\n'
    << "<- pf = " << pf << '\n'
    << "-> nearest[pf > -1](pf) = " << eve::nearest[pf > -1](pf) << '\n';
    return 0;
    }