◆ minmod()

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

This function object computes the smallest of its parameter if they share the same sign, zero instead.

Header <boost/simd/function/minmod.hpp>
Notes

Using minmod(x, y) is similar to x*y > 0 ? min(x, y) : 0

See also
min, minnum, minnummag, minmag
Example:
#include <boost/simd/arithmetic.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, -2.0f, -5.0f, 0.0f };
pack_ft qf = { 4.0f, 3.0f, -2.0f, 4.0f };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> bs::minmod(pf, qf) = " << bs::minmod(pf, qf) << '\n';
float xf = 3.0f, yf = 4.0f;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " -> bs::minmod(xf, yf) = " << bs::minmod(xf, yf) << '\n'
<< " -> bs::minmod(xf,-yf) = " << bs::minmod(xf, -yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (3, -2, -5, 0)
<- qf = (4, 3, -2, 4)
-> bs::minmod(pf, qf) = (3, 0, -5, 0)
---- scalar
xf = 3
yf = 4
-> bs::minmod(xf, yf) = 3
-> bs::minmod(xf,-yf) = 0