## ◆ trunc()

 Value boost::simd::trunc ( Value const & x )

This function object computes the truncation toward Zero of its parameter.

Notes
• the call to trunc(x) is similar to sign(x)*floor(abs(x))
• For floating point number it is also one of the two ouputs of the modf function. And we have:
trunc(x) + frac(x) == x;
except for nans
Decorators
• std_ for floating entries call std::trunc
Alias:

fix

abs, frac, floor, sign, modf, itrunc
Example:
#include <boost/simd/arithmetic.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/function/enumerate.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 8>;
int main()
{
pack_ft pf = bs::enumerate<pack_ft>(-2.56, 0.51);
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " -> bs::trunc(pf) = " << bs::trunc(pf) << '\n';
float xf = 3.2f, yf = -3.2f;
std::cout
<< "---- scalar" << '\n'
<< " <- xf = " << xf<< '\n'
<< " -> bs::trunc(xf) = " << bs::trunc(xf) << '\n'
<< " <- yf = " << yf << '\n'
<< " -> bs::trunc(yf) = " << bs::trunc(yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (-2.56, -2.05, -1.54, -1.03, -0.52, -0.00999999, 0.5, 1.01)
-> bs::trunc(pf) = (-2, -2, -1, -1, -0, -0, 0, 1)
---- scalar
<- xf = 3.2
-> bs::trunc(xf) = 3
<- yf = -3.2
-> bs::trunc(yf) = -3