Quaternion conjugate with -Ofast incorrect result

Summary

Not sure if it is a bug or if I just should not use fastmath but following program gives true when compiled via g++ main.cpp and gives false when compiled via g++ main.cpp -Ofast

Main.cpp:

#include <iostream>
#include "eigen3/Eigen/Geometry"
int main()
{
    srand((unsigned int) time(0));
    Eigen::Quaterniond q = Eigen::Quaterniond::UnitRandom();
    if( q.vec() == -q.conjugate().vec() )
        std::cout<<"true\n";
    else
        std::cout<<"false\n";
    return 0;
}

Environment

  • Operating System : Linux
  • Architecture : x64
  • Eigen Version : 3.4.0
  • Compiler Version : Gcc7.5.0
  • Compile Flags : see example
  • Vector Extension : no clue

Code worked with -Ofast and eigen 3.3.5 (Geometry_SSE.h)

Edited by Michael Dluhosch