E.V.E
v2023.02.15

◆ sub

eve::sub = {}
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_value_t<Ts ...> sub(Ts ... xs) noexcept;
}
Definition: value.hpp:31
constexpr callable_sub_ sub
Computes the sum of its arguments.
Definition: sub.hpp:76
Definition: abi.hpp:18
typename eve::detail::common_value_impl< void, Ts... >::type common_value_t
Computes the SIMD-compatible common type between all Ts.
Definition: common_value.hpp:50

Parameters

Return value

If the arguments are \((x_i)_{0\le i\le n}\) The value of \(x_0-\sum_1^n x_i\) is returned.

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'
<< " -> sub(pi, qi) = " << eve::sub(pi, qi) << '\n'
<< " -> pi - qi = " << 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'
<< " -> sub(xi, yi) = " << eve::sub(xi, yi) << '\n'
<< " -> xi - yi = " << xi - yi << '\n'; // C++ promotion to int
auto k = kumi::tuple{pf, pf, pf, 1};
std::cout << "---- multi parameters" << '\n'
<< " -> sub(pi,pi,pi,1) = " << eve::sub(pi, pi, pi, 1) << '\n'
<< " -> sub(k) = " << eve::sub(k) << '\n'
<< " -> sub(kumi::tuple{pf, pf}) = " << eve::sub( kumi::tuple{pf, pf}) << '\n'
<< " -> sub(kumi::tuple{pf, 1.0f) = " << eve::sub( kumi::tuple{pf, 1.0f}) << '\n'
<< " -> sub(kumi::tuple{1.0f, pf) = " << eve::sub( kumi::tuple{1.0f, pf}) << '\n'
<< " -> saturated(sub)(pi,12,pi,pi) = " << eve::saturated(eve::sub)(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::sub[mask](x, ...) provides a masked version of sub which is equivalent to if_else(mask, sub(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'
    << " -> sub[pi > qi](pi, qi) = " << eve::sub[pi > qi](pi, qi) << '\n';
    return 0;
    }
  • eve::saturated

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

    Take care that for signed integral entries this kind of operation is highly order dependant. We do not advise to use it for more than 2 parameters.

    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(sub)(pi, qi) = " << eve::saturated(eve::sub)(pi, qi) << '\n';
    return 0;
    }