◆ touint()

as_integer_t<Value, unsigned> boost::simd::touint ( Value const &  x)

This function object converts its parameter to unsigned integer by truncation.

Header <boost/simd/function/touint.hpp>
Notes

touint cast a floating value to the unsigned signed integer value of the same bit size.

This is done by C casting for scalars and corresponding intrinsic in simd (if available).

Peculiarly, that implies that the behaviour of this function on invalid or negative entries is not defined and possibly unpredictable.

If you intend to use Nan, Inf or negative entries, consider using saturated_(touint) instead.

Decorators
  • saturated_ (See Decorators) as stated above ensures good behaviour on limiting values.
See also
toint, tofloat
Example:
#include <boost/simd/arithmetic.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/constant/inf.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = {-1.0f, 2.6f, 3.4f, bs::Inf<float>()};
pack_it pi = { -1, 2, 3, bs::Inf<std::int16_t>() };
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> bs::touint(pf) = " << bs::touint(pf) << '\n'
<< "-> saturated_(bs::touint)(pf) = " << bs::saturated_(bs::touint)(pf) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> bs::touint(pi) = " << bs::touint(pi) << '\n'
<< "-> saturated_(bs::touint)(pi) = " << bs::saturated_(bs::touint)(pi) << '\n';
float xf = -2.50f;
std::int16_t xi = -1;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bs::touint(xf) = " << bs::touint(xf) << '\n'
<< "-> saturated_(bs::touint)(xf) = " << bs::saturated_(bs::touint)(xf) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> bs::touint(xi) = " << bs::touint(xi) << '\n'
<< "-> saturated_(bs::touint)(xi) = " << bs::saturated_(bs::touint)(xi) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (-1, 2.6, 3.4, inf)
-> bs::touint(pf) = (4294967295, 2, 3, 0)
-> saturated_(bs::touint)(pf) = (0, 2, 3, 4294967295)
<- pi = (-1, 2, 3, 32767)
-> bs::touint(pi) = (65535, 2, 3, 32767)
-> saturated_(bs::touint)(pi) = (0, 2, 3, 32767)
---- scalar
<- xf = -2.5
-> bs::touint(xf) = 0
<- xi = -1
-> bs::touint(xi) = 65535