◆ majority()

as_logical_t<Value> boost::simd::majority ( Value const &  x,
Value const &  y,
Value const &  z 
)

This function object returns True if at least two inputs are not Zero else False.

Header <boost/simd/function/majority.hpp>
Note

Using majority(x,y,z) is similar to: (x!= 0)+(y!= 0)+(z!= 0) >= 2

Example:
#include <boost/simd/predicates.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = { 0.0f, 1.0f, -1.0f, -2.0f };
pack_ft qf = { 0.0f, 0.0f, -0.0f, -2.0f };
pack_ft rf = { 0.0f, 1.0f, -0.0f, -2.0f };
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qf = " << qf << '\n'
<< "<- rf = " << rf << '\n'
<< "-> bs::majority(pf, qf, rf) = " << bs::majority(pf, qf, rf) << '\n';
float xf = 1.0f;
float yf = 2.0;
float zf = 0.0;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "<- zf = " << zf << '\n'
<< "-> bs::majority(xf, yf, zf) = " << bs::majority(xf, yf, zf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (0, 1, -1, -2)
<- qf = (0, 0, -0, -2)
<- rf = (0, 1, -0, -2)
-> bs::majority(pf, qf, rf) = (false, true, false, true)
---- scalar
<- xf = 1
<- yf = 2
<- zf = 0
-> bs::majority(xf, yf, zf) = true