E.V.E  0.1-beta

◆ nearest

eve::nearest = {}
inlineconstexpr

Callable object computing the nearest operation.

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

Members Functions

Member Effect
operator() the nearest operation
operator[] Construct a conditional version of current function object

template< value T > auto operator()( T x ) const noexcept;

Parameters

x: value.

Return value

Computes elementwise the integer nearest to x.

If x is an exact half-integer the rouding 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_DOWNWARD version.

The call to nearest(a) is equivalent to the call round(a, to_nearest).


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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/nearest.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;
}
constexpr callable_nearest_ nearest
Callable object computing the nearest operation.
Definition: nearest.hpp:79
Wrapper for SIMD registers.
Definition: wide.hpp:65