Callable object performing the division of multiple values.
Required header: #include <eve/function/div.hpp>
Members Functions
Member | Effect |
operator() | Computes the absolute value of its parameter |
operator[] | Construct a conditional version of current function object |
Parameters
x
Instance of eve::value.
xs
: Instances of eve::value. Behavior is undefined if the expected result type is integral and any xs
is equal to 0.
Return value
A value of the common compatible type of x
and all xs
containing the elementwise division of x
by all xs
. The result is semantically equivalent to x/mul(xs...)
With two parameters, the call div(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 scalar types is the original one and so can lead to automatic promotion.
auto operator[]( conditional_expression auto cond ) const noexcept;
Higher-order function generating a masked version of eve::div
Parameters
cond
: conditional expression
Return value
A Callable object so that the expression div[cond](x0,xs...)
is equivalent to if_else(cond,div(x0,xs...),x0)
Supported decorators
eve::saturated
Required header: #include <eve/function/saturated/div.hpp>
The expression eve::saturated(eve::div)(x, xs...)
computes the saturated division of x
by all xs
. The result is semantically equivalent to x/saturated(mul)(xs...)
but is always defined even if the denominator is 0.
The relevant cases are just in fact the division by 0 for integral types in which case the result is `eve::Valmin(as(x))` or [eve::Valmax(as(x))
](ref eve::valmax) according to the dividend sign, and the division of `eve::Valmin(as(x))` by -1 that produces `eve::Valmax(as(x))`.
eve::toward_zero
The call toward_zero(div)(x, y)
computes trunc(div(x, y))
.
eve::downward
The call downward(div)(x, y)
computes floor(div(x, y))
.
eve::upward
The call upward(div)(x, y)
computes ceil(div(x, y))
.
eve::to_nearest
The call to_nearest(div)(x, y)
computes nearest(div(x,y))
.
eve::diff, eve::diff_1st, eve::diff_2nd, eve::diff_3rd, eve::diff_nth
Required header: #include <eve/function/diff/div.hpp>
The expression eve::diff_nth<N>(eve::div)(x, xs...)
computes the derivative of the division over the Nth parameter.
Example
See it live on Compiler Explorer
#include <eve/function/div.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
w_t
pi = {3, 2, 3, 32700}, qi = {4, 1, 1, 100};
std::cout << "---- simd" << '\n'
<<
" <- pi = " <<
pi <<
'\n'
<< " <- qi = " << qi << '\n'
<<
" -> div(pi, qi) = " <<
eve::div(
pi, qi) <<
'\n'
<<
" -> pi / qi = " <<
pi / qi <<
'\n';
std::int16_t xi = -32768, yi = -1;
std::cout << "---- scalar" << '\n'
<< " xi = " << xi << '\n'
<< " yi = " << yi << '\n'
<<
" -> div(xi, yi) = " <<
eve::div(xi, yi) <<
'\n'
<< " -> xi / yi = " << xi / yi << '\n'
<< " -> std::int16_t( xi / yi) = "<< std::int16_t( xi / yi) << '\n';
return 0;
}
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
constexpr callable_div_ div
Callable object performing the division of multiple values.
Definition: div.hpp:118
Wrapper for SIMD registers.
Definition: wide.hpp:65