C++ 为什么这些双打的返回值是 -1.#IND?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7476177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why are the return values of these doubles -1.#IND?
提问by Chai
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.
有作为 -1.#IND 返回的值。除此之外,正值是正常的,如 1.34543。
Why does this happen? How do I solve it?
为什么会发生这种情况?我该如何解决?
回答by Jon Cage
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:
正如 Frederic 所说,这是由在 Windows 上使用 Visual Studio 构建的应用程序格式化的“非数字”的结果。约翰 D 库克有一个很好的参考:
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.
Windows 将 NaN 显示为 -1.#IND(“IND”表示“不确定”),而 Linux 显示 nan。
...
简而言之,如果您得到 1.#INF 或 inf,请查找溢出或除以零。如果得到 1.#IND 或 nan,请查找非法操作。
Watch out for truncations if you do any sort of formatting with your string; I've encountered related issueswhen handling these sorts of errors myself.
如果您对字符串进行任何格式化,请注意截断;我在自己处理这些类型的错误时遇到了相关问题。
回答by viraj
In my experience -1.#IND
comes from imaginary numbers. So, doing cout << sqrt(-1.);
should output -1.#IND
根据我的经验,-1.#IND
来自虚数。所以,做cout << sqrt(-1.);
应该输出-1.#IND