In Ubuntu18.04, I got issue with eigen library with array inversion function, when compile with -O3 and -ffast-math option, the number in the even number of column have wrong sign for them.
The steps to re-create:
- docker run -v $PWD:/work -it ubuntu:18.04
- apt update
- apt install libeigen3-dev -y Install gcc version 10.3.0
- apt install software-properties-common -y
- add-apt-repository ppa:ubuntu-toolchain-r/test -y && apt update
- apt install gcc-10 gcc-10-base gcc-10-doc g++-10 -y
- Create the file using eigen, I use file name eigen_test.cpp:
#include <iostream>
#include <eigen3/Eigen/Eigen>
int main()
{
Eigen::Matrix4d t;
t << 1.0, -0.0, 0.0, -0.0,
0.0, 1.0, -0.0, -0.0,
0.0, 0.0, 1.0, -0.0,
0.0, 0.0, 0.0, 1.0;
std::cout << "Original matrix: \n" <<t << std::endl;
std::cout << "Inversed matrix: \n" << t.inverse() << std::endl;
}
- Compile with ffast-math option:
$ g++-10 eigentest.cpp -O3 -ffast-math -o a.out
$ ./a.out
Original matrix:
1 -0 0 -0
0 1 -0 -0
0 0 1 -0
0 0 0 1
Inversed matrix:
1 -0 -0 0
-0 -1 -0 -0
-0 0 1 0
-0 -0 -0 -1
- Re-compile without ffast-math option:
$ g++-10 eigentest.cpp -O3 -o a.out
$ ./a.out
Original matrix:
1 -0 0 -0
0 1 -0 -0
0 0 1 -0
0 0 0 1
Inversed matrix:
1 0 -0 0
-0 1 0 0
-0 -0 1 -0
0 0 -0 1
The output of two results are different, the one compiled with option: -ffast-math get -1 in the (2, 2) and (4, 4) position, and they are wrong, the correct value should be 1. Does anyone know why?