◆ sign()

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

This function object returns the sign of x.

i.e. -1, 0 or 1, depending on the fact x is less than Zero, Zero or greater than Zero.

For floating, the sign of Nan is Nan, the sign of Mzero is also Zero.

See also
signnz, is_negative, is_positive, bitofsign
Header <boost/simd/function/sign.hpp>
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, 2.0f, -1.0f, 0.5f};
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> bs::sign(pf) = " << bs::sign(pf) << '\n';
float xf = 2.0f;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bs::sign(xf) = " << bs::sign(xf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1, 0.5)
-> bs::sign(pf) = (1, 1, -1, 1)
---- scalar
<- xf = 2
-> bs::sign(xf) = 1