dimanche 28 juin 2015

Wrong results using auto with Eigen

I got different results using auto and using Vector when in sum two vectors

my code:

#include "stdafx.h"
#include <iostream>
#include "D:\externals\eigen_3_1_2\include\Eigen\Geometry"

typedef Eigen::Matrix<double, 3, 1>       Vector3;


void foo(const Vector3& Ha, volatile int j) 
{



    const auto resAuto = Ha + Vector3(0.,0.,j * 2.567);
    const Vector3 resVector3 = Ha + Vector3(0.,0.,j * 2.567);

    std::cout << "resAuto = " << resAuto <<std::endl;
    std::cout << "resVector3 = " << resVector3 <<std::endl;

}

int main(int argc, _TCHAR* argv[])
{
    Vector3 Ha(-24.9536,-29.3876,65.801);
    Vector3 z(0.,0.,2.567);

    int j = 7;

    foo(Ha,j);
    return 0;
}

The results:

    resAuto = -24.9536, -29.3876,65.801
    resVector3 = -24.9536,-29.3876,83.77
    Press any key to continue . . .

i understand that Eigen does internal optimization that generate different results. but it looks like bug in Eigen and C++11

Aucun commentaire:

Enregistrer un commentaire