std::pair boost::simd::two_add ( Value const & x, Value const & y )

This function object computes two reals of the type of the inputs (in an std::pair) r0 and r1 such that:

r0 = x + y
r1 = r0 -(x + y)

using perfect arithmetic.

Its main usage is to be able to compute sum of reals and the residual error using IEEE 754 arithmetic.

Example:
#include <boost/simd/arithmetic.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/constant/eps.hpp>
#include <iostream>
#include <iomanip>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = { 1.0f, -2.0f, 3.0f, -4.0 };
pack_ft qf(bs::Eps<float>());
pack_ft s, e;
std::cout
<< "---- simd" << std::setprecision(8) << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " std::tie(s, e) = bs::two_add(pf, qf) " << '\n'
<< " -> s = " << s << '\n'
<< " -> e = " << e << '\n';
float xf = 3.0f, yf = bs::Eps<float>();
float ss, se;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " std::tie(ss, se) = bs::two_add(xf, yf) " << '\n'
<< " -> ss = " << ss << '\n'
<< " -> se = " << se << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, -2, 3, -4)
<- qf = (1.1920929e-07, 1.1920929e-07, 1.1920929e-07, 1.1920929e-07)