Why are the return values of these doubles -1.#IND?

让人想犯罪 __ 提交于 2019-12-17 09:56:45

问题


I have :

double score = cvMatchContourTrees( CT1, CT2, CV_CONTOUR_TREES_MATCH_I1, 0.0 );
        cout<<score<<endl;

There are values returned as -1.#IND. Other than that, the positive values are normal, like 1.34543.

Why does this happen? How do I solve it?


回答1:


As Frederic says, it's the result of a 'Not a Number' being formatted by an application built with visual studio on windows. John D Cook has an excellent reference:

Windows displays a NaN as -1.#IND ("IND" for "indeterminate") while Linux displays nan.

...

In short, if you get 1.#INF or inf, look for overflow or division by zero. If you get 1.#IND or nan, look for illegal operations.

Watch out for truncations if you do any sort of formatting with your string; I've encountered related issues when handling these sorts of errors myself.




回答2:


std::cout << (0/0.f);
// Output: -1.#IND

It's NaN.




回答3:


In my experience -1.#IND comes from imaginary numbers. So, doing cout << sqrt(-1.); should output -1.#IND



来源:https://stackoverflow.com/questions/7476177/why-are-the-return-values-of-these-doubles-1-ind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!