E.V.E  0.1-beta

◆ trunc

eve::trunc = {}
inlineconstexpr

Callable object computing the trunc operation.

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

Members Functions

Member Effect
operator() the trunc 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 integral part of x with the same sign as x.

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

The call to trunc(a) is equivalent to the call toward_zero(round)(a).


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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • tolerant

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

    The expression tolerant(trunc)(x, tol) computes a tolerant truncated value for x, where x must be a floating value.

    • If tol is a floating_value computes the floor with a tolerance tol using Hagerty's FL5 function.
    • If tol is an integral_value n compute the floor of the next nth representable value in the x type.
    • If tol is omitted the tolerance is taken to 3 times the machine \(\epsilon\) in the x type (3*eps(as(x))).
  • eve::diff, eve::diff_1st, eve::diff_nth

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

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

Example

See it live on Compiler Explorer

#include <eve/function/trunc.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'
<< "-> trunc(pf) = " << eve::trunc(pf) << '\n';
float xf = -32.768f;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> trunc(xf) = " << eve::trunc(xf) << '\n';
return 0;
}
constexpr callable_trunc_ trunc
Callable object computing the trunc operation.
Definition: trunc.hpp:91
Wrapper for SIMD registers.
Definition: wide.hpp:65