E.V.E  0.1-beta

◆ round

eve::round = {}
inlineconstexpr

Callable object computing the round operation.

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

Members Functions

Member Effect
operator() the round 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 call to round(a) is equivalent to the call nearest(a).


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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • eve::downward

    The expression downward(round)(x) is equivalent to floor(x).

  • eve::upward

    The expression upward(round)(x) is equivalent to ceil(x).

  • eve::to_nearest

    The expression to_nearest(round)(x) is equivalent to nearest(x).

  • eve::toward_zero

    The expression toward_zero(round)(x) is equivalent to trunc(x).

  • eve::diff, eve::diff_1st, eve::diff_nth

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

    The expression diff(round)(x) computes the derivative of the function at x.

Example

See it live on Compiler Explorer

#include <eve/function/round.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'
<< "-> round(pf) = " << eve::round(pf) << '\n'
<< "-> upward(round)(pf) = " << eve::upward(eve::round)(pf) << '\n'
<< "-> downward(round)(pf) = " << eve::downward(eve::round)(pf) << '\n'
<< "-> to_nearest(round)(pf) = " << eve::to_nearest(eve::round)(pf) << '\n'
<< "-> toward_zero(round)(pf) = " << eve::toward_zero(eve::round)(pf) << '\n';
float xf = -32.768f;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> round(xf) = " << eve::round(xf) << '\n'
<< "-> upward(round)(xf) = " << eve::upward(eve::round)(xf) << '\n'
<< "-> downward(round)(xf) = " << eve::downward(eve::round)(xf) << '\n'
<< "-> to_nearest(round)(xf) = " << eve::to_nearest(eve::round)(xf) << '\n'
<< "-> toward_zero(round)(xf) = " << eve::toward_zero(eve::round)(xf) << '\n';
return 0;
}
constexpr toward_zero_type const toward_zero
Higher-order Callable Object imbuing rounding toward zero semantic onto other Callable Objects.
Definition: roundings.hpp:163
constexpr upward_type const upward
Higher-order Callable Object imbuing upward rounding semantic onto other Callable Objects.
Definition: roundings.hpp:160
constexpr downward_type const downward
Higher-order Callable Object imbuing rounding downard semantic onto other Callable Objects.
Definition: roundings.hpp:161
constexpr to_nearest_type const to_nearest
Higher-order Callable Object imbuing rounding to nearest semantic onto other Callable Objects.
Definition: roundings.hpp:162
constexpr callable_round_ round
Callable object computing the round operation.
Definition: round.hpp:96
Wrapper for SIMD registers.
Definition: wide.hpp:65