E.V.E
v2022.09.01

◆ trunc

eve::trunc = {}
inlineconstexpr

Computes the integral part of x with the same sign as x.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
T trunc(T x) noexcept;
}
constexpr callable_trunc_ trunc
Computes the integral part of x with the same sign as x.
Definition: trunc.hpp:82
Definition: all_of.hpp:22

Parameters

Return value

The integral part of x with the same sign as x.

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

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

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'
<< "-> 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;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

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

    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 truncation with a tolerance tol using Hagerty's FL5 function.
    • If tol is an integral_value n compute the truncation of the next or previous 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))).

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    #include <iomanip>
    int main()
    {
    wide_ft pf = {-1.0f, -1.3f, -1.5f, -1.7f, 2.0f, 2.3f, 2.5f, 2.7f};
    pf += 3*eve::eps(eve::as<float>());
    std::cout << "---- simd" << std::setprecision(8) << '\n'
    << "<- pf = " << pf << '\n'
    << "-> trunc(pf) = " << eve::trunc(pf) << '\n'
    << "-> tolerant(trunc)(pf) = " << eve::tolerant(eve::trunc)(pf) << '\n'
    << "-> tolerant(trunc)(pf, 1) = " << eve::tolerant(eve::trunc)(pf, 1) << '\n';
    return 0;
    }
    constexpr tolerant_type const tolerant
    Higher-order Callable Object imbuing a less strict semantic onto other Callable Objects.
    Definition: fuzzy.hpp:147
    Lightweight type-wrapper.
    Definition: as.hpp:29