E.V.E  0.1-beta

◆ saturate

eve::saturate = {}
inlineconstexpr

Callable object computing the saturation of a value in a type.

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

Members Functions

Member Effect
operator() computation of the saturation of a value in a type
operator[] Construct a conditional version of current function object

template< real_value T, real_scalar_value Target>
auto operator()( T const& x, as_<Target> const& t) const noexcept;

Parameters

x: value to saturate.

t: Type wrapper instance embedding the type to saturate x to.

Return value

For an x of real value Target, the expression:

T r = saturate(x, as_<Target>{});
constexpr callable_saturate_ saturate
Callable object computing the saturation of a value in a type.
Definition: saturate.hpp:94

is semantically equivalent to:

T vmin=static_cast<T>(Valmin<Target>());
T vmax=static_cast<T>(Valmax<Target>());
T r = convert(clamp(x,vmi,vmax),as(x));
constexpr callable_clamp_ clamp
Callable object clamping a value between two others.
Definition: clamp.hpp:104
constexpr callable_convert_ convert
Callable object converting a value to another type.
Definition: convert.hpp:87
Lightweight type-wrapper.
Definition: as.hpp:29
Warning
Note Saturation operated by eve::saturate may lead to Undefined Behaviors if it implies conversions that are themselves U.B.

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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/saturate.hpp>
#include <eve/constant/valmax.hpp>
#include <eve/wide.hpp>
#include <iostream>
using int_16 = eve::as<std::int16_t>;
using int_64 = eve::as<std::int64_t>;
int main()
{
wide_ft pf = {-1.0f, 2.3f, 45000.7f, -64768.6f};
wide_it pi = {-1, 2, -3, eve::valmax(eve::as<std::int64_t>())};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> saturate(pf, int_64()_) = " << eve::saturate(pf, int_64()) << '\n'
<< "-> saturate(pf, int_16()) = " << eve::saturate(pf, int_16()) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> saturate(pi, as(eve::as<double>())) = " << eve::saturate(pi, eve::as<double>()) << '\n';
double xf = -64768.4f;
std::int64_t xi = -64768;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> saturate(xf, int_64()) = " << eve::saturate(xf, int_64()) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> saturate(xi, as(eve::as<double>())) = " << eve::saturate(xi, eve::as<double>()) << '\n';
return 0;
}
constexpr callable_valmax_ valmax
Callable object computing the greatest representable value.
Definition: valmax.hpp:53
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
Wrapper for SIMD registers.
Definition: wide.hpp:65