E.V.E
v2023.02.15

◆ saturate

eve::saturate = {}
inlineconstexpr

Computes the saturation of a value in a type.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
{ template<value From, scalar_value To>
To bit_cast operator()(From x, as<To> t) noexcept;
}
constexpr callable_bit_cast_ bit_cast
Computes a a bitwise reinterpretation of an object.
Definition: bit_cast.hpp:64
Definition: abi.hpp:18
Lightweight type-wrapper.
Definition: as.hpp:29

Parameters

Template parameters

  • To: scalar type to which each element of x is saturated

Return value

For an x of real value Target, the call saturate(x, as_<Target>{}) returns elementwise a value of type Target which is the conversion of x clamped between the smallest and largest values of Target

Note
Saturation operated by eve::saturate may lead to Undefined Behaviors if it implies conversions that are themselves U.B.

Example

#include <eve/module/core.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_saturate_ saturate
Computes the saturation of a value in a type.
Definition: saturate.hpp:62
constexpr callable_valmax_ valmax
Computes the the greatest representable value.
Definition: valmax.hpp:55
constexpr callable_pi_ pi
Callable object computing the constant .
Definition: pi.hpp:49
Wrapper for SIMD registers.
Definition: wide.hpp:65