作者:ccmmm | 来源:互联网 | 2023-09-25 19:28
HeresaweirdcalculationerrorinVB.NET.Ivesimplifiedmyproblemtothefollowing.Icanwrite
Here's a weird calculation error in VB.NET. I've simplified my problem to the following. I can write:
在VB.NET中有一个奇怪的计算错误。我将我的问题简化为以下内容。我可以写:
Console.WriteLine(-0.78125 ^ 2.5)
and get -0.53947966093944366
.
-0.53947966093944366。
But if I change it to Console.WriteLine((-0.78125 + 0) ^ 2.5)
, I get -1.#IND
.
但是如果我改变Console.WriteLine(-0.78125(-0.78125 + 0)^),我得到1。#印第安纳州。
Or, if it try:
或者,如果它试一试:
Dim D as Double = -0.78125
Console.WriteLine(D ^ 2.5)
I also get -1.#IND
.
我也得到1。#印第安纳州。
I can only get the calculation to return a result if I use a single literal number in the expression, but when I use a variable of any data type I get -1.#IND
.
只有在表达式中使用单个文字数时,我才能让计算返回结果,但是当我使用任何数据类型的变量时,我会得到-1.#IND。
I've read the other posts that explaining "-1.#IND", but they indicate that one of the numbers in the expression is NaN, which is not the case here. Why is this happening?
我读过其他解释“-1”的文章。但是它们表明表达式中的一个数字是NaN,这里不是这样的。为什么会这样?
1 个解决方案