◆ min()

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

This function object computes the smallest of its parameter.

Header <boost/simd/function/min.hpp>
Notes
For any given value x and y of type T:

Using min(x, y) is similar to (x < y) ? x : y which is the standard behaviour.

With this definition min(x, Nan) should return x...

On some systems the intrinsic used returns Nan as soon x or y is a nan. So the real definition of our min function must add: but if y is Nan the result is system dependent.

This can be corrected using the pedantic_ decorator that ensures the standard behaviour at a cost.

Decorators
  • pedantic_ ensures the standard behaviour.
  • std_ call std::min.
See also
min, minnum, minnummag, minmag, minmod
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, -0.0f, 0.0f };
pack_ft qf = { 4.0f, -1.0f, 0.0f, bs::Nan<float>() };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> bs::min(pf, qf) = " << bs::min(pf, qf) << '\n'
<< " -> bs::pedantic_(bs::min)(pf, qf) = " << bs::pedantic_(bs::min)(pf, qf) << '\n'
<< " -> bs::std_(bs::min)(pf, qf) = " << bs::std_(bs::min)(pf, qf) << '\n';
float xf = 3.0f, yf = 4.0f;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " -> bs::min(xf, yf) = " << bs::min(xf, yf) << '\n'
<< " -> bs::pedantic_(bs::min)(xf, yf) = " << bs::pedantic_(bs::min)(xf, yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (3, -2, -0, 0)
<- qf = (4, -1, 0, -nan)
-> bs::min(pf, qf) = (3, -2, -0, 0)
-> bs::pedantic_(bs::min)(pf, qf) = (3, -2, -0, 0)
-> bs::std_(bs::min)(pf, qf) = (3, -2, -0, 0)
---- scalar
xf = 3
yf = 4
-> bs::min(xf, yf) = 3
-> bs::pedantic_(bs::min)(xf, yf) = 3