E.V.E
v2023.02.15

◆ round

eve::round = {}
inlineconstexpr

Computes the integer nearest to the input.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

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

Parameters

Return value

The integer nearest to x.

For complex inputs the round 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'
<< "-> 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
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve;round[mask](x) provides a masked version of eve::round which is equivalent to if_else (mask, round(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'
    << "-> round[pf>-1.4f](pf) = " << eve::round[pf>-1.4f](pf) << '\n'
    << "-> upward(round[pf>-1.4f])(pf) = " << eve::upward(eve::round[pf>-1.4f])(pf) << '\n'
    << "-> downward(round[pf>-1.4f])(pf) = " << eve::downward(eve::round[pf>-1.4f])(pf) << '\n'
    << "-> to_nearest(round[pf>-1.4f])(pf) = " << eve::to_nearest(eve::round[pf>-1.4f])(pf) << '\n'
    << "-> toward_zero(round[pf>-1.4f])(pf) = " << eve::toward_zero(eve::round[pf>-1.4f])(pf) << '\n';
    return 0;
    }
  • eve::downward

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

  • eve::upward

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

  • eve::to_nearest

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

  • eve::toward_zero

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

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    w_t pf = {3.2, 2.5, 3.5, 3.6, 0.3, -2.4, -3.5, -3-2};
    std::cout << "---- simd" << '\n'
    << " <- pi = " << pf << '\n'
    << " <- toward_zero(round)(pf) = " << eve::toward_zero(eve::round)(pf) << '\n'
    << " -> upward(round)(pf) = " << eve::downward(eve::round)(pf) << '\n'
    << " -> downward(round)(pf) = " << eve::upward(eve::round)(pf) << '\n'
    << " -> to_nearest(round)(pf) = " << eve::to_nearest(eve::round)(pf) << '\n';
    return 0;
    }