E.V.E
v2023.02.15

◆ sum_of_prod

eve::sum_of_prod = {}
inlineconstexpr

Computes the sum of products operation with better accuracy than the naive formula.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::floating_value T
T sum_of_prod(T x, U y, V z, W t ) noexcept;
}
Definition: value.hpp:83
constexpr callable_sum_of_prod_ sum_of_prod
Computes the sum of products operation with better accuracy than the naive formula.
Definition: sum_of_prod.hpp:79
Definition: abi.hpp:18

Parameters

Return value

The value of x*y+z*t, with better precision if correct fma is available, is returned.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <iomanip>
int main()
{
wf_t xf = {3, 2, 1, 0}, zf = {4, 1, 2, 100};
wf_t tf = -(xf+4*eve::eps(eve::as<float>())), yf = zf-4*eve::eps(eve::as<float>());
std::cout << "---- simd" << std::setprecision(8) << '\n'
<< " <- xf = " << xf << '\n'
<< " <- yf = " << yf << '\n'
<< " <- tf = " << tf << '\n'
<< " <- zf = " << zf << '\n'
<< " -> xf*yf+tf*zf = " << (xf*yf)+(tf*zf) << '\n'
<< " -> sum_of_prod(xf, yf, tf, zf) = " << eve::sum_of_prod(xf, yf, tf, zf) << '\n';
return 0;
}
constexpr callable_eps_ eps
Computes the the machine epsilon.
Definition: eps.hpp:63
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • eve::raw

    The call eve::raw(eve::diff_of_prod)(x, y, z, t) computes a raw version of eve::sum_of_prod, i.e. the naive formula

  • eve::pedantic

    The call eve::pedantic(eve::sum_of_prod)(x, y, z, t) computes a pedantic version of eve::sum_of_prod ensuring better accuracy in any case.

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    #include <iomanip>
    int main()
    {
    wf_t xf = {3, 2, 1, 0}, zf = {4, 1, 2, 100};
    wf_t tf = -(xf+4*eve::eps(eve::as<float>())), yf = zf-4*eve::eps(eve::as<float>());
    std::cout << "---- simd" << std::setprecision(8) << '\n'
    << " <- xf = " << xf << '\n'
    << " <- yf = " << yf << '\n'
    << " <- tf = " << tf << '\n'
    << " <- zf = " << zf << '\n'
    << " -> xf*yf+tf*zf = " << (xf*yf)+(tf*zf) << '\n'
    << " -> pedantic(sum_of_prod)(xf, yf, tf, zf) = " << eve::pedantic(eve::sum_of_prod)(xf, yf, tf, zf) << '\n';
    return 0;
    }
    constexpr pedantic_type const pedantic
    Higher-order Callable Object imbuing more standard semantic onto other Callable Objects.
    Definition: pedantic.hpp:56