## ◆ round()

 IEEEValue boost::simd::round ( IEEEValue const & x, IntegerValue const & n = 0 )

This function object computes the rounding away from zero of its parameter.

Notes:
• With a second integral parameter round(x,n) rounds aways from 0 to n digits: this is similar to round(x*exp10(n))*exp10(-n)
• n default to 0,
• n > 0: round to n digits to the right of the decimal point.
• n = 0: round to the nearest integer.
• n < 0: round to n digits to the left of the decimal point.
• aways from 0 means that half integer values are rounded to the nearest integer of greatest absolute value

The current rounding mode has no effect.

• If x is $$\pm\infty$$ or $$\pm0$$, it is returned, unmodified
• If x is a NaN, a NaN is returned
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.5678, 0.5123);
pack_ft qf(1234.5678f);
pack_it ni = bs::enumerate<pack_it>(-3, 1);
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " -> bs::round(pf) = " << bs::round(pf) << '\n'
<< " <- ni = " << ni << '\n'
<< " -> bs::round(qf, ni) = " << bs::round(qf, ni) << '\n'
<< " -> bs::round(pf, 2) = " << bs::round(pf, 2) << '\n';
float xf = 3.225f;
std::cout
<< "---- scalar" << '\n'
<< " <- xf = " << xf<< '\n'
<< " -> bs::round(xf) = " << bs::round(xf) << '\n'
<< " -> bs::round(xf, 2) = " << bs::round(xf, 2) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (-2.5678, -2.0555, -1.5432, -1.0309, -0.5186, -0.00629997, 0.506, 1.0183)
-> bs::round(pf) = (-3, -2, -2, -1, -1, -0, 1, 1)
<- ni = (-3, -2, -1, 0, 1, 2, 3, 4)
-> bs::round(qf, ni) = (1000, 1200, 1230, 1235, 1234.6, 1234.57, 1234.57, 1234.57)
-> bs::round(pf, 2) = (-2.57, -2.06, -1.54, -1.03, -0.52, -0.01, 0.51, 1.02)
---- scalar
<- xf = 3.225
-> bs::round(xf) = 3
-> bs::round(xf, 2) = 3.23