This forum has been archived. All content is frozen. Please use KDE Discuss instead.

The result of matrix multiplication is different from c++

Tags: None
(comma "," separated)
lixiang
Registered Member
Posts
2
Karma
0
At the same time, I multiply tow matrix using Eigen and standard C++. But the results are not the same, though very similar. I do not the reason. And I check all the details but no problem can be found.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is due to floating-point rounding. With floating-point arithmetic, operators + and * are not associative anymore, so the result will depend on the operation order. Moreover, the result will also slightly differ whether you are using the FPU or SSE unit.
lixiang
Registered Member
Posts
2
Karma
0
For example, matrix a and b are C++ style, and matrix c and d are eigen style. Now the sum of a*b and c*d is the same, but each coeff is not the same. For later derivation calculation, the different result will generate different results.

ggael wrote:This is due to floating-point rounding. With floating-point arithmetic, operators + and * are not associative anymore, so the result will depend on the operation order. Moreover, the result will also slightly differ whether you are using the FPU or SSE unit.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes, that's normal.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]