◆ rem()

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

This function object computes the remainder of the two parameters of the same type with or without option.

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

For any value a and b of same type rem({option, }a, b) returns the quotient of a by b respective to the option specified.

  • Options

    With no option this function is equivalent to x-div(fix, x, y)*y

    option may be ceil, floor, fix, round, nearbyint (in the namespace booost::simd). Each option provides the same result as x-div(option, x, y)*y.

  • Supported types

    unsigned types are not supported but for the option fix, as in other cases results can be negative

  • Limiting values for floating entries:
    • if x is +/-inf , Nan is returned
    • if x is +/-0 and y is not 0, 0 is returned (if the sign of x matters the pedantic_ decorated version returns x)
    • if y is +/-0, Nan is returned
    • if either argument is NaN, Nan is returned
Decorators
  • pedantic_ insure better limiting cases (see above note)
  • std_ allow direct calls to some libc++ function:
    • option fix calls std::fmod
    • option nearbyint calls std::remainder
    • The other options have no standard equivalent
See also
div
Example:
#include <boost/simd/arithmetic.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = { 5.0f, -5.0f, 3.0f, 5.0f };
pack_ft qf = { 2.0f, 2.0f, 3.0f, -2.0f };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> bs::rem(pf, qf) = " << bs::rem(pf, qf) << '\n'
<< " -> bs::rem(bs::fix, pf, qf) = " << bs::rem(bs::fix, pf, qf) << '\n'
<< " -> bs::rem(bs::ceil, pf, qf) = " << bs::rem(bs::ceil, pf, qf) << '\n'
<< " -> bs::rem(bs::floor, pf, qf) = " << bs::rem(bs::floor, pf, qf) << '\n'
<< " -> bs::rem(bs::round, pf, qf) = " << bs::rem(bs::round, pf, qf) << '\n'
<< " -> bs::rem(bs::nearbyint, pf, qf) = " << bs::rem(bs::nearbyint, pf, qf) << '\n';
float xf = 5.0, yf = 2.0f;
std::cout
<< "---- scalar" << '\n'
<< " <- xf = " << xf << '\n'
<< " <- yf = " << yf << '\n'
<< " -> bs::rem( xf, yf) = " << bs::rem(xf, yf) << '\n'
<< " -> bs::rem(bs::fix, xf, yf) = " << bs::rem(bs::fix, xf, yf) << '\n'
<< " -> bs::rem(bs::ceil, xf, yf) = " << bs::rem(bs::ceil, xf, yf) << '\n'
<< " -> bs::rem(bs::floor, xf, yf) = " << bs::rem(bs::floor, xf, yf) << '\n'
<< " -> bs::rem(bs::round, xf, yf) = " << bs::rem(bs::round, xf, yf) << '\n'
<< " -> bs::rem(bs::nearbyint, xf, yf) = " << bs::rem(bs::nearbyint, xf, yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (5, -5, 3, 5)
<- qf = (2, 2, 3, -2)
-> bs::rem(pf, qf) = (1, -1, 0, 1)
-> bs::rem(bs::fix, pf, qf) = (1, -1, 0, 1)
-> bs::rem(bs::ceil, pf, qf) = (-1, -1, 0, 1)
-> bs::rem(bs::floor, pf, qf) = (1, 1, 0, -1)
-> bs::rem(bs::round, pf, qf) = (-1, 1, 0, -1)
-> bs::rem(bs::nearbyint, pf, qf) = (1, -1, 0, 1)
---- scalar
<- xf = 5
<- yf = 2
-> bs::rem( xf, yf) = 1
-> bs::rem(bs::fix, xf, yf) = 1
-> bs::rem(bs::ceil, xf, yf) = -1
-> bs::rem(bs::floor, xf, yf) = 1
-> bs::rem(bs::round, xf, yf) = -1
-> bs::rem(bs::nearbyint, xf, yf) = 1