◆ unary_minus()

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

This function object returns the elementwise unary minus of the parameter.

Infix notation can be used with operator '-'

Header <boost/simd/function/unary_minus.hpp>
Note:
  • r = unary_minus(x) is equivalent to r = -x for SIMD types.
Warning
Take care that the infix notation in scalar integral mode encurs a possible promotion of the type as C++ rules state.
Decorators
  • saturated_ ensures that saturated_(unary_minus)(Valmin<T>()) is Valmin<T>()
See also
minus, unary_plus
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::unary_minus(pf) = " << bs::unary_minus(pf) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> bs::unary_minus(pi) = " << bs::unary_minus(pi) << '\n'
<< "-> bs::saturated_(bs::unary_minus(pi)) = " << bs::saturated_(bs::unary_minus)(pi) << '\n'
<< "-> -pi = " << (-pi) << '\n';
float xf = -32768.0f;
std::int16_t xi = -32768;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> bs::unary_minus(xf) = " << bs::unary_minus(xf) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> bs::unary_minus(xi) = " << bs::unary_minus(xi) << '\n'
<< "-> bs::saturated_(bs::unary_minus(xi)) = " << bs::saturated_(bs::unary_minus)(xi) << '\n'
<< "-> -xi = " << (-xi) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (-1, 2, -3, -32768)
-> bs::unary_minus(pf) = (1, -2, 3, 32768)
<- pi = (-1, 2, -3, -32768)
-> bs::unary_minus(pi) = (1, -2, 3, -32768)
-> bs::saturated_(bs::unary_minus(pi)) = (1, -2, 3, 32767)
-> -pi = (1, -2, 3, -32768)
---- scalar
<- xf = -32768
-> bs::unary_minus(xf) = 32768
<- xi = -32768
-> bs::unary_minus(xi) = -32768
-> -xi = 32768