## ◆ two_prod()

 std::pair boost::simd::two_prod ( 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 prod 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 <boost/simd/function/inc.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::inc(bs::Eps<float>()));
pack_ft s, e;
std::tie(s, e) = bs::two_prod(pf, qf);
std::cout
<< "---- simd" << std::setprecision(8) << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " std::tie(s, e) = bs::two_prod(pf, qf) " << '\n'
<< " -> s = " << s << '\n'
<< " -> e = " << e << '\n';
float xf = 3.0f, yf = bs::inc(bs::Eps<float>());
float ss, se;
std::tie(ss, se) = bs::two_prod(xf, yf);
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " std::tie(ss, se) = bs::two_prod(xf, yf) " << '\n'
<< " -> ss = " << ss << '\n'
<< " -> se = " << se << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, -2, 3, -4)
<- qf = (1.0000001, 1.0000001, 1.0000001, 1.0000001)
std::tie(s, e) = bs::two_prod(pf, qf)
-> s = (1.0000001, -2.0000002, 3.0000005, -4.0000005)
-> e = (0, 0, -1.1920929e-07, 0)
---- scalar
xf = 3
yf = 1.0000001
std::tie(ss, se) = bs::two_prod(xf, yf)
-> ss = 3.0000005
-> se = -1.1920929e-07