Native floating point precision

I'm having issues with floating point precision using Eigen.

I have two Eigen::MatrixXd; the first matrix A(nx1) contains only the numbers of natural numbers, and the second matrix B(nx1) contains one column filled with the same real number (ex: -0.714312).

I need to calculate the following Eigen::MatrixXd:

const auto exponential = [](double x)
{ return std::exp(x); };


MatrixXd W = B.unaryExpr(exponential);
MatrixXd residuals = A - W;

The problem is that when I print the sum of the balances:

cout << residuals.sum();
// output = 6.16951e-06

I get a different value by doing the same operation using R and the same input matrices.

Using R-matrices, I get -2.950208e-09. Although the sum of the elements A, Band Wis the same in both C++, and in R.

+4
1

, R x90 FPU (80 ), Eigen SSE (64 /double ). Matrix<long double,Dynamic,Dynamic> , FPU x87.

0

Source: https://habr.com/ru/post/1616623/


All Articles