◆ if_neg()

Value1 boost::simd::if_neg ( Value0 const &  c,
Value1 const &  x 
)

This function object conditionally returns -x if c is True and x otherwise.

Header <boost/simd/function/if_neg.hpp>
Example:
#include <boost/simd/boolean.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/constant/nan.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = { 3.0f, 0.0f, -3.0f, -0.0 };
pack_ft qf = { 3.0f, 0.5f, -3.0f, 1.0f };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> bs::negif(pf, qf) = " << bs::if_neg(pf, qf) << '\n';
std::int32_t xf = 3, yf = 0, zf = 5;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " zf = " << zf << '\n'
<< " -> bs::negif(xf, zf) = " << bs::if_neg(xf, zf) << '\n'
<< " -> bs::negif(yf, zf) = " << bs::if_neg(yf, zf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (3, 0, -3, -0)
<- qf = (3, 0.5, -3, 1)
-> bs::negif(pf, qf) = (-3, 0.5, 3, 1)
---- scalar
xf = 3
yf = 0
zf = 5
-> bs::negif(xf, zf) = -5
-> bs::negif(yf, zf) = 5