## ◆ max()

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

This function object computes the largest of its parameter.

Notes
For any given value x and y of type T:

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

With this definition max(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 max 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::max.
min, maxnum, maxnummag, maxmag
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::max(pf, qf) = " << bs::max(pf, qf) << '\n'
<< " -> bs::pedantic_(bs::max)(pf, qf) = " << bs::pedantic_(bs::max)(pf, qf) << '\n'
<< " -> bs::std_(bs::max)(pf, qf) = " << bs::std_(bs::max)(pf, qf) << '\n';
float xf = 3.0f, yf = 4.0f;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " -> bs::max(xf, yf) = " << bs::max(xf, yf) << '\n'
<< " -> bs::pedantic_(bs::max)(xf, yf) = " << bs::pedantic_(bs::max)(xf, yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (3, -2, -0, 0)
<- qf = (4, -1, 0, -nan)
-> bs::max(pf, qf) = (4, -1, -0, 0)
-> bs::pedantic_(bs::max)(pf, qf) = (4, -1, -0, 0)
-> bs::std_(bs::max)(pf, qf) = (4, -1, -0, 0)
---- scalar
xf = 3
yf = 4
-> bs::max(xf, yf) = 4
-> bs::pedantic_(bs::max)(xf, yf) = 4