E.V.E
v2023.02.15

◆ clamp

eve::clamp = {}
inlineconstexpr

Computes the largest integer not greater than the input.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::ordered_value T, eve::ordered_value U, eve::value V>
auto clamp(T x, U lo, V hi) noexcept;
}
constexpr callable_clamp_ clamp
Computes the largest integer not greater than the input.
Definition: clamp.hpp:94
constexpr callable_hi_ hi
Computes the most significant half of each lane.
Definition: hi.hpp:54
constexpr callable_lo_ lo
Computes the least significant half of each lane.
Definition: lo.hpp:54
Definition: abi.hpp:18

Parameters

Return value

Each element of the result contains:

  • lo, if x is less than lo.
  • hi, if hi is less than x.
  • otherwise x.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_t xi = {2, -3, 0, 4};
wide_t lo = {3, -2, -10, 0};
wide_t hi = {4, -1, 0, 5};
std::cout << "---- ximd" << '\n'
<< " <- xi = " << xi << '\n'
<< " <- lo = " << lo << '\n'
<< " <- hi = " << hi << '\n'
<< " -> clamp(xi, lo, hi) = " << eve::clamp(xi, lo, hi) << '\n';
float sxi = 3, slo = 3, shi = 4;
std::cout << "---- scalar" << '\n'
<< " sxi = " << sxi << '\n'
<< " slo = " << slo << '\n'
<< " shi = " << shi << '\n'
<< " -> clamp(sxii, slo, shi) = " << eve::clamp(sxi, slo, shi) << '\n';
return 0;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve;clamp[mask](x, ...) provides a masked version of eve::clamp which is equivalent to if_else (mask, clamp(x, ...), x).

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_t xi = {2, -3, 0, 4};
    wide_t lo = {3, -2, -10, 0};
    wide_t hi = {4, -1, 0, 5};
    std::cout << "---- ximd" << '\n'
    << " <- xi = " << xi << '\n'
    << " <- lo = " << lo << '\n'
    << " <- hi = " << hi << '\n'
    << " -> clamp[xi > -2](xi, lo, hi) = " << eve::clamp[xi > -2](xi, lo, hi) << '\n';
    return 0;
    }