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

Arithmetic error?

Tags: None
(comma "," separated)
pandishar
Registered Member
Posts
10
Karma
0

Arithmetic error?

Thu Aug 08, 2013 5:54 am
I'm rather mystified by this odd error.

Code: Select all
ScalarEval(const Eigen::VectorXd &x)
{
std::cout << "x " << x << std::endl;
std::cout << "scaling " << inputScaling << std::endl;
Eigen::VectorXd scaledX = x / inputScaling;
std::cout << "scaledX " << scaledX << std::endl;
}

where inputScaling is a class member double. This produces:
Code: Select all
x  0.502607  0.109873   0.94413 -0.326851 -0.310484  0.845046
scaling 0.121233
scaledX  0.0609327  0.0133202    0.11446 -0.0396252  -0.037641   0.102448


This is wrong, somehow it multiplied!

Switch the division line to:
Code: Select all
Eigen::VectorXd scaledX = 1.0/inputScaling * x ;


produces the correct:
Code: Select all
x 0.502607 0.109873 0.94413 -0.326851 -0.310484 0.845046
scaling 0.121836
scaledX 4.12527 0.901808 7.74918 -2.68271 -2.54838 6.93592


I'm using the stable release 3.2.0 under g++ 4.8.0 with c++11 enabled.
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Arithmetic error?

Thu Aug 08, 2013 7:10 am
This is strange indeed. Does up- or down-grading the compiler help? Changing the compiler flags? I don't know what else to suggest as long as we don't have a self-contained example.
pandishar
Registered Member
Posts
10
Karma
0

Re: Arithmetic error?

Thu Aug 08, 2013 11:46 pm
Well, I should have known better. It went away on a clean compile - I forgot to do this when I just upgraded Eigen. Sorry for the mistake.

That exact swap of operators is an odd way to fail, although I suppose I've seen the compiler do very strange things if it gets into an inconsistent partly-compiled state.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]