E.V.E
v2022.09.01

◆ add

eve::add = {}
inlineconstexpr

Computes the sum of its arguments.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value... Ts >
eve::common_compatible_t<Ts ...> add(Ts ... xs) noexcept;
}
Definition: value.hpp:31
constexpr callable_add_ add
Computes the sum of its arguments.
Definition: add.hpp:83
Definition: all_of.hpp:22

Parameters

Return value

The value of the sum of the arguments is returned.

Note
  • Take care that for floating entries, the addition is only 'almost' associative. This call performs additions in reverse incoming order.
  • 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()
{
w_t pi = {3, 2, -32700, 32700}, qi = {4, 1, -100, 100};
wf_t pf = {3, 2.5, -32.7, 1327.43}, qf = {4.2, 1.5, -100.834, 10.02};
std::cout << "---- simd" << '\n'
<< " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
<< " -> add(pi, qi) = " << eve::add(pi, qi) << '\n'
<< " -> pi + qi = " << pi + qi << '\n'
<< " -> saturated(add)(pi, qi) = " << eve::saturated(eve::add)(pi, qi) << '\n'
<< " -> pf + qf = " << pf + qf << '\n';
std::int16_t xi = 100, yi = 32700;
std::cout << "---- scalar" << '\n'
<< " <- xi = " << xi << '\n'
<< " <- yi = " << yi << '\n'
<< " -> add(xi, yi) = " << eve::add(xi, yi) << '\n'
<< " -> xi + yi = " << xi + yi << '\n'; // C++ promotion to int
std::cout << "---- multi parameters" << '\n'
<< " -> add(pi,pi,pi,1) = " << eve::add(pi, pi, pi, 1) << '\n'
<< " -> saturated(add)(pi,12,pi,pi) = " << eve::saturated(eve::add)(pi, 12, pi,pi) << '\n';
return 0;
}
constexpr saturated_type const saturated
Higher-order Callable Object imbuing saturation semantic onto other Callable Objects.
Definition: saturated.hpp:68
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::add[mask](x, ...) provides a masked version of add which is equivalent to if_else(mask, eve::add(x, ...), x)

    Example

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

    The call eve::saturated(eve::add)(...) computes a saturated version of eve::add.

    Take care that for signed integral entries this kind of addition is not associative at all. This call perform saturated additions in reverse incoming order.

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    w_t pi = {3, 2, -32700, 32700}, qi = {4, 1, -100, 100};
    std::cout << "---- simd" << '\n'
    << " <- pi = " << pi << '\n'
    << " <- qi = " << qi << '\n'
    << " -> saturated(add)(pi, qi) = " << eve::saturated(eve::add)(pi, qi) << '\n';
    std::int16_t a = -32700;
    std::int16_t b = -32767;
    std::int16_t c = 32767;
    std::cout << "---- scalar" << '\n'
    << " <- a = " << a << '\n'
    << " <- b = " << b << '\n'
    << " <- c = " << c << '\n'
    << " -> saturated(add)(a, b, c) = " << eve::saturated(eve::add)(a, b, c) << '\n'
    << " -> saturated(add)(c, b, a) = " << eve::saturated(eve::add)(c, b, a) << '\n';
    return 0;
    }