C++ sqrt 返回 -1.#IND000000000000

发布于 2024-10-12 09:49:25 字数 225 浏览 2 评论 0原文

具体来说:

我正在做一些数学运算,并且应用程序不断崩溃,因为当“某些”数字被开方时,广泛使用的双精度碰巧获得值:-1.#IND000000000000... 这是什么?不定?无限?太大装不下?不是完美的平方根?有什么办法可以解决这个问题吗? 提前致谢! 编辑:我如何检查双精度值是否具有此值?我尝试过: if (x == 0x-1.#IND000000000000) 和其他变体,但没有用。是否可以检查变量是否具有该值?

In specific:

Im doing some math operations, and the application keeps crashing because a double that is widely used happens to get the value: -1.#IND000000000000 when "some" numbers are sqrt'ed...
What is this? Indefinite? Infinite? Too big to fit? Not a perfect Square Root? Is there any way to solve this?
Thanks in advance!
EDIT: How can i check if a double has this value ? I tried: if (x == 0x-1.#IND000000000000) and other variations but did not work. Is it possible to check to see if a variable has this value ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

十秒萌定你 2024-10-19 09:49:25

实际上,字符串 -1.#IND000000000000 不是一个值,由函数返回,但它是 QNaN 的常见表示形式之一,Quiet Not -a-Number,表示无效数字的特殊 IEEE-754 值,不会导致异常(还有 SNaNSignalling NaN、如果启用的话,这会导致浮点异常)。造成这种情况的常见原因是调用一个带有超出其域的参数的函数。

Actually, the string -1.#IND000000000000 is not a value, returned by a function, but it is one of a common representations of a QNaN, Quiet Not-a-Number, the special IEEE-754 value representing the invalid number, that won't cause the exception (there are also SNaN, Signalling NaN, which would cause the floating point exception, if enabled). The common cause of this is calling a function with argument out of it's domain.

Bonjour°[大白 2024-10-19 09:49:25

NaN(例如“不确定”和“无穷大”)可以通过检查 x == x 来检测(对于 NaN 为 false,对于任何有限数为 true)。

NaNs (such as the "indeterminate" you have and "infinity") can be detected by checking x == x (it's false for NaN and true for any finite number).

转身泪倾城 2024-10-19 09:49:25

#IND000000000000 表示无效的数值。这通常称为 QNaN(安静非数字)值,因为它表示不确定类型,但不会导致计算失败。

您尝试确定其平方根的难以捉摸的数字很可能是数,并且未为其定义该值。有关详细信息,请参阅维基百科

解决该问题首先需要您确定问题发生的位置。这意味着您要么需要使用调试器自行单步调试并观察变量的值,要么发布您的代码以便我们可以做同样的事情。

The value #IND000000000000 represents an invalid numeric value. This is often called a QNaN (Quiet Not-A-Number) value because it represents an indeterminate type but does not cause calculations to fail.

Chances are, the elusive numbers whose square root you're attempting to determine are negative numbers, for which that value is not defined. See Wikipedia for more information.

Solving it will first require you to determine where the problem is occurring. That means you either need to step through yourself it with a debugger and watch the values of the variables, or post your code so that we can do the same.

合久必婚 2024-10-19 09:49:25

如果参数为负数,则发生域错误,将全局变量 errno 设置为值 EDOM。

If the argument is negative, a domain error occurs, setting the global variable errno to the value EDOM.

骄傲 2024-10-19 09:49:25

如果不使用复杂类型,任何低于 0 的值的 sqrt 都会导致异常。

Without using a complex type, sqrt of any value below 0 is meant to cause an exception.

冰雪之触 2024-10-19 09:49:25

这是一个 NaN(不是数字)。这意味着您使用负参数调用了 sqrt。

干杯&呵呵,

It's a NaN (Not A Number). It means you've called sqrt with a negative argument.

Cheers & hth.,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文