◆ divides()

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

Function object implementing divides capabilities.

Perform the quotient of two parameters of the same type. Infix notation can be used with operator '/'.

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

As usual the simd division is often more expansive than the other arithmetic operators and using the rec function or shift_right function can be sometimes handy to gain some cycles.

Decorators
  • saturated_ (See Decorators) computes the saturated division. The only difference is to allow for integer types to divide Valmin by -1 returning Valmax. In the regular case (no decorator) the result is undefined.
See also
div, rem, rec, shift_right
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, -32700.0f};
pack_ft qf = { 2.0f, -1.0f, -3.0f, 32721 };
pack_it pi = { 1, -2, -2, -32768 };
pack_it qi = { 2, -1, -3, -1 };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> bs::divides(pf, qf) = " << bs::divides(pf, qf) << '\n'
<< " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
<< " -> bs::divides(pi, qi) = " << bs::divides(pi, qi) << '\n'
<< " -> bs::saturated_(bs::divides)(pi, qi) = " << bs::saturated_(bs::divides)(pi, qi) << '\n';
float xf = 32767.0f, yf = -32000.0f;
std::int16_t xi = 32767, yi = -32000;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " -> bs::divides(xf, yf) = " << bs::divides(xf, yf) << '\n'
<< " xi = " << xi << '\n'
<< " yi = " << yi << '\n'
<< " -> bs::divides(xi, yi) = " << bs::divides(xi, yi) << '\n'
<< " -> bs::saturated_(bs::divides)(xi, yi) = " << bs::saturated_(bs::divides)(xi, yi) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, -2, -3, -32700)
<- qf = (2, -1, -3, 32721)
-> bs::divides(pf, qf) = (0.5, 2, 1, -0.999358)
<- pi = (1, -2, -2, -32768)
<- qi = (2, -1, -3, -1)
-> bs::divides(pi, qi) = (0, 2, 0, -32768)
-> bs::saturated_(bs::divides)(pi, qi) = (0, 2, 0, 32767)
---- scalar
xf = 32767
yf = -32000
-> bs::divides(xf, yf) = -1.02397
xi = 32767
yi = -32000
-> bs::divides(xi, yi) = -1
-> bs::saturated_(bs::divides)(xi, yi) = -1