Bug 475 - exp not returning inf when it should
: exp not returning inf when it should
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Core - general
: 3.0
: All All
: Normal critical
Assigned To: Nobody
:
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-06-14 03:37 UTC by Ben Wang
Modified: 2012-06-14 11:08 UTC (History)
2 users (show)



Attachments

Description Ben Wang 2012-06-14 03:37:29 UTC
The result for this simple program doesn't seem to be correct:

#include <iostream>
#include <eigen3/Eigen/Dense>

using namespace std;

int main(int argc, char* argv[]) {
  Eigen::MatrixXf m(2, 2);
  m << 91.61, 1, 1, 1;
  m = m.array().exp();
  cout << m << endl;
  cout << m.sum() << endl;
}

2.40614e+38 2.71828
2.71828 2.71828
2.40614e+38

The exp(91.61) should give an 'inf' result but it didn't. However, if I trim
down the matrix to a smaller size, it works fine again:

#include <iostream>
#include <eigen3/Eigen/Dense>

using namespace std;

int main(int argc, char* argv[]) {
  Eigen::MatrixXf m(1, 2);
  m << 91.61, 1;
  m = m.array().exp();
  cout << m << endl;
  cout << m.sum() << endl;
}

    inf 2.71828
inf

Can someone help debug why this is happening? I'd like to have 'inf' as a
result when it's indeed overflowing, instead of getting some random (albeit
large) number.

Thanks!
Comment 1 Gael Guennebaud 2012-06-14 10:40:42 UTC
Thank you for the report. This was due to vectorization.  Fixed:


https://bitbucket.org/eigen/eigen/changeset/dbd64aae2795/
changeset:   dbd64aae2795
user:        ggael
date:        2012-06-14 10:38:39
summary:     fix bug 475: .exp() now returns +inf when overflow occurs (SSE)

https://bitbucket.org/eigen/eigen/changeset/7437d1687f7d/
changeset:   7437d1687f7d
branch:      3.0
user:        ggael
date:        2012-06-14 10:38:39
summary:     fix bug 475: .exp() now returns +inf when overflow occurs (SSE)
(transplanted from dbd64aae279527f558021ce98c0950402443d460)
Comment 2 Ben Wang 2012-06-14 10:46:54 UTC
Thanks for the quick fix!

Could you kindly let me know how I can get a diff/patch for this fix, if it's
not too big? I'd like to use it before the next release is out. Thanks!
Comment 3 Ben Wang 2012-06-14 11:08:21 UTC
Never mind. I found it. Thanks and have a nice day!

Note You need to log in before you can comment on or make changes to this bug.