E.V.E
v2022.09.01

◆ div

eve::div = {}
inlineconstexpr

Computes the division of multiple values.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value... Ts >
eve::common_compatible_t<T, Ts ...> div(Ts ... xs) noexcept;
}
Definition: value.hpp:31
constexpr callable_div_ div
Computes the division of multiple values.
Definition: div.hpp:101
Definition: all_of.hpp:22

Parameters

Return value

If the arguments are \((x_i)_{0\le i\le n}\) The value of \(x/\prod_1^n x_i\) is returned.

Note
  • With two parameters, the call div(x, y) is equivalent to x / y if x or y is an simd value.
  • Although the infix notation with / is supported for two parameters, the / operator on standard scalar types is the original one and so can lead to automatic promotion.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wf_t pf = {3, 2, 3, 32700}, qf = {4, 1, 1, 100};
std::cout << "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> div(pf, qf) = " << eve::div(pf, qf) << '\n'
<< " -> pf / qf = " << pf / qf << '\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' // C++ promotion to int
<< " -> std::int16_t( xi / yi) = "<< std::int16_t( xi / yi) << '\n';
return 0;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

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

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wf_t pf = {31, 2, 3, 32700}, qf = {4, 8, 16, 100};
    std::cout << "---- simd" << '\n'
    << " <- pf = " << pf << '\n'
    << " <- qf = " << qf << '\n'
    << " -> div[pf > qf](pf, qf) = " << eve::div[pf > qf](pf, qf) << '\n';
    return 0;
    }
  • eve::saturated

    The expression eve::saturated(eve::div)(x, xs...) computes the saturated division of x by all xs. The result is semantically equivalent to saturated(div)(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))`.

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    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'
    << " -> saturated(div(xi, yi)) = " << eve::saturated(eve::div)(xi, yi) << '\n';
    return 0;
    }
    constexpr saturated_type const saturated
    Higher-order Callable Object imbuing saturation semantic onto other Callable Objects.
    Definition: saturated.hpp:68
  • eve::toward_zero, eve::downward, eve::upward, eve::to_nearest

    The calls d(div)(x, y) where d is one of these 4 decorators produce respectively

    * `eve::trunc (div(x, y))` for eve::toward_zero.
    * `eve::floor (div(x, y))` for deve::downward.
    * `eve::ceil (div(x, y))`  for eve::upward.
    * `eve::nearest (div(x,y))`for eve::to_nearest.
    

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wf_t pf = {3034, 200, 333, 32700}, qf = {4, 7, 13, 100};
    std::cout << "---- simd" << '\n'
    << " <- pf = " << pf << '\n'
    << " <- qf = " << qf << '\n'
    << " -> toward_zero(div)(pf, qf) = " << eve::toward_zero(eve::div)(pf, qf) << '\n'
    << " -> downward(div)(pf, qf) = " << eve::downward(eve::div)(pf, qf) << '\n'
    << " -> upward(div)(pf, qf) = " << eve::upward(eve::div)(pf, qf) << '\n'
    << " -> to_nearest(div)(pf, qf) = " << eve::to_nearest(eve::div)(pf, qf) << '\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