Weird behaviour loading double value from array

asked 2016-03-12 02:31:36 -0500

Hi all, I've found this really weird behaviour when loading a double value from array into a cv::Mat object. I do the following:

double foo_array[] = { -0.837231 };                     
cv::Mat foo(1, 1, cv::DataType<double>::type, foo_array);
std::cout << "foo: " << foo << std::endl;

and I got the output below:

foo: [-0.8372309999999999]

Why do I not get the exact value I entered? For any other numeric value it seems to behave properly. Any help would be greatly appreciated, thanks

edit retag flag offensive close merge delete

Comments

2

I think precision used in opencv is better for cout. try this

double xxx=-0.837231;

cout<<std::setprecision(17)<< xxx<<endl;

You will get same result.

LBerger gravatar imageLBerger ( 2016-03-12 04:16:36 -0500 )edit