◆ saturate()

template<typename Target >
Value boost::simd::saturate ( Value const &  x)

This function object returns the saturated value of the first input in the template parameter type, but in the same type as the argument.

Header <boost/simd/function/saturate.hpp>
Semantic:

For every parameter of type T and type Target

T r = saturate<Target>(x)

is similar to:

if (x > Inf<Target>()) r = T(Inf<Target>());
else if (x < Minf<Target>()) r = T(Minf<Target>());
else r = x;
See also
Minf, Inf, Valmax, Valmin
Note

Let us recall that Valmin and Minf (resp. Valmax and Inf) are identical if Target is an integer type.

Example:
#include <boost/simd/ieee.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = {1.0f, 200.0f, -150.0f, 0.5f};
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> bs::saturate<std::int8_t>(pf) = " << bs::saturate<std::int8_t>(pf) << '\n';
float xf = 2.0f;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bs::saturate<std::int8_t>(xf) = " << bs::saturate<std::int8_t>(xf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 200, -150, 0.5)
-> bs::saturate<std::int8_t>(pf) = (1, 127, -128, 0.5)
---- scalar
<- xf = 2
-> bs::saturate<std::int8_t>(xf) = 2