◆ copysign()

Value boost::simd::copysign ( Value const &  x,
Value const &  y 
)

This function object returns x with the sign of y.

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