E.V.E
v2022.03.00

◆ floor

eve::floor = {}
inlineconstexpr

Computes the largest integer not greater than the input.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
T floor(T x) noexcept;
}
constexpr callable_floor_ floor
Computes the largest integer not greater than the input.
Definition: floor.hpp:80
Definition: all_of.hpp:22

Parameters

Return value

The largest integer not greater than `x`.

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

For complex inputs the floor 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'
<< "-> floor(pf) = " << eve::floor(pf) << '\n';
float xf = -32.768f;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> floor(xf) = " << eve::floor(xf) << '\n';
return 0;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

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

    The expression tolerant(floor)(x, tol) computes a tolerant floor 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, computes 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))).
    #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'
    << "-> floor(pf) = " << eve::floor(pf) << '\n'
    << "-> tolerant(floor)(pf) = " << eve::tolerant(eve::floor)(pf) << '\n'
    << "-> tolerant(floor)(pf, 1) = " << eve::tolerant(eve::floor)(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