E.V.E  0.1-beta

◆ rem

eve::rem = {}
inlineconstexpr

Callable object computing the rem operation.

Required header: #include <eve/function/rem.hpp>

Members Functions

Member Effect
operator() the rem operation
operator[] Construct a conditional version of current function object

template< value T, value U > auto operator()( T x, U y ) const noexcept requires compatible< T, U >;

Parameters

x, y: values.

Return value

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

The result type is the common compatible type of the two parameters.

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

Warning
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.

auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::rem

Parameters

cond : conditional expression

Return value

A Callable object so that the expression rem[cond](x, ...) is equivalent to if_else(cond,rem(x, ...),x)


Supported decorators

  • 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

See it live on Compiler Explorer

#include <eve/function/rem.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 value.
Definition: pi.hpp:54
constexpr callable_rem_ rem
Callable object computing the rem operation.
Definition: rem.hpp:112
Wrapper for SIMD registers.
Definition: wide.hpp:65