[go: up one dir, main page]

exp not returning inf when it should

Submitted by Ben Wang

Assigned to Nobody

Link to original bugzilla bug (#475)
Version: 3.0

Description

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!

Edited by Eigen Bugzilla