E.V.E
v2022.03.00

◆ rem

eve::rem = {}
inlineconstexpr

Computes the remainder after division.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T, eve::value U>
eve::common_compatible_t<T, U> rem(T x, U y) noexcept;
}
constexpr callable_rem_ rem
Computes the remainder after division.
Definition: rem.hpp:106
Definition: all_of.hpp:22

Parameters

Return value

Return the remainder after division division of x by y and is semantically equivalent to x- eve::trunc ( eve:div(x, y) )*y.

The call rem(x, y) is equivalent to x % y if x or y is an simd value.

Note
  • Although the infix notation with % is supported, the % operator on standard integral scalar type is the original one and so can lead to automatic promotion. Moreover due to C++ limitations % is not available for scalar floating point values.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
w_t pi = {3, 2, 3, 32700}, qi = {4, 2, 2, 101};
std::cout << "---- simd" << '\n'
<< " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
<< " -> rem(pi, qi) = " << eve::rem(pi, qi) << '\n'
<< " -> pi % qi = " << pi % qi << '\n';
std::int16_t xi = 32700, yi = 101;
std::cout << "---- scalar" << '\n'
<< " xi = " << xi << '\n'
<< " yi = " << yi << '\n'
<< " -> rem(xi, yi) = " << eve::rem(xi, yi) << '\n'
<< " -> xi % yi = " << xi % yi << '\n';
return 0;
}
constexpr callable_pi_ pi
Callable object computing the constant .
Definition: pi.hpp:49
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve::rem[mask](x, ...) provides a masked version of rem which is equivalent to if_else(mask, rem(x, ...), x)

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    w_t pi = {3, 2, 3, 32700}, qi = {4, 2, 0, 101};
    std::cout << "---- simd" << '\n'
    << " <- pi = " << pi << '\n'
    << " <- qi = " << qi << '\n'
    << " -> rem[qi!= 0](pi, qi) = " << eve::rem[qi!= 0](pi, qi) << '\n';
    return 0;
    }
  • eve::toward_zero

    The call toward_zero(rem)(x, y) computes x-towardzero_(div)(x, y)*y. For floating point entries this call is similar to std::fmod. In particular:

    • If x is \(\pm0\) and y is not zero, \(\pm0\) is returned.
    • If x is \(\pm\infty\), and y is not NaN, NaN is returned.
    • If y is \(\pm0\), NaN is returned.
    • If y is \(\pm\infty\) and x is finite, x is returned.
    • If either argument is a Nan, NaN is returned.
  • eve::downward

    The call downward(rem)(x, y) computes x-downward(div)(x, y)*y.

  • eve::upward

    The call upward(rem)(x, y) computes x-upward(div)(x, y)*y. It is not defined for unsigned values as the result can be negative.

  • eve::to_nearest

    The call to_nearest(rem)(x, y) computes x-to_nearest(div)(x,y)*y. It is not defined for unsigned values as the result can be negative. For floating point entries this call is similar to std::remainder. In particular:

    • If x is \(\pm\infty\), NaN is returned
    • If y is \(\pm0\), NaN is returned
    • If either argument is a Nan, NaN is returned

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    w_t pi = {3, 2, 3, 32700}, qi = {4, 2, 2, 101};
    std::cout << "---- simd" << '\n'
    << " <- pi = " << pi << '\n'
    << " <- qi = " << qi << '\n'
    << " <- toward_zero(rem)(pi, qi) = " << eve::toward_zero(eve::rem)(pi, qi) << '\n'
    << " -> upward(rem)(pi, qi) = " << eve::downward(eve::rem)(pi, qi) << '\n'
    << " -> downward(rem)(pi, qi) = " << eve::upward(eve::rem)(pi, qi) << '\n'
    << " -> to_nearest(rem)(pi, qi) = " << eve::to_nearest(eve::rem)(pi, qi) << '\n'
    << " -> pi % qi = " << pi % qi << '\n';
    return 0;
    }
    constexpr toward_zero_type const toward_zero
    Higher-order Callable Object imbuing rounding toward zero semantic onto other Callable Objects.
    Definition: roundings.hpp:163
    constexpr upward_type const upward
    Higher-order Callable Object imbuing upward rounding semantic onto other Callable Objects.
    Definition: roundings.hpp:160
    constexpr downward_type const downward
    Higher-order Callable Object imbuing rounding downard semantic onto other Callable Objects.
    Definition: roundings.hpp:161
    constexpr to_nearest_type const to_nearest
    Higher-order Callable Object imbuing rounding to nearest semantic onto other Callable Objects.
    Definition: roundings.hpp:162