## ◆ sqr()

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

This function computes the square of its parameter.

Decorators
• saturated_ for integer entries ensure that sqr(x) is never strictly less than x
sqrt, sqr_abs
Example:
#include <boost/simd/arithmetic.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
using pack_it = bs::pack <std::int16_t,4>;
int main()
{
pack_ft pf = {-1.0f, 2.0f, -3.0f, -32768.0f};
pack_it pi = {-1, 2, -3, -32768 };
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> bs::sqr(pf) = " << bs::sqr(pf) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> bs::sqr(pi) = " << bs::sqr(pi) << '\n'
<< "-> bs::saturated_(bs::sqr(pi)) = " << bs::saturated_(bs::sqr)(pi) << '\n';
float xf = -32768.0f;
std::int16_t xi = -32768;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bs::sqr(xf) = " << bs::sqr(xf) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> bs::sqr(xi) = " << bs::sqr(xi) << '\n'
<< "-> bs::saturated_(bs::sqr(xi)) = " << bs::saturated_(bs::sqr)(xi) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (-1, 2, -3, -32768)
-> bs::sqr(pf) = (1, 4, 9, 1.07374e+09)
<- pi = (-1, 2, -3, -32768)
-> bs::sqr(pi) = (1, 4, 9, 0)
-> bs::saturated_(bs::sqr(pi)) = (1, 4, 9, 32767)
---- scalar
<- xf = -32768
-> bs::sqr(xf) = 1.07374e+09
<- xi = -32768
-> bs::sqr(xi) = 0
-> bs::saturated_(bs::sqr(xi)) = 32767