不准确的算术运算结果

时间:2017-04-25 16:06:23

标签: .net vb.net binary cpu-architecture

涉及计算[2 ^ 63] - [(2 ^ 63)-2 ^ 9]范围内的数值的算术运算会产生不准确的结果。这意味着以下数字被视为相等:

Dim c0 As Boolean = (2 ^ 63 - 100) = 2 ^ 63 'True
Dim c1 As Boolean = ((2 ^ 63)) - (2 ^ 62) = 2 ^ 62 'True
Dim c2 As Boolean = ((2 ^ 63) - 1) - (2 ^ 62) = 2 ^ 62 'True
Dim c3 As Boolean = ((2 ^ 63) - 10) - (2 ^ 62) = 2 ^ 62 ' True
Dim c4 As Boolean = ((2 ^ 63) - 100) - (2 ^ 62) = 2 ^ 62 'True
Dim c4a As Boolean = ((2 ^ 63) - 512) - (2 ^ 62) = 2 ^ 62 'True
Dim c4b As Boolean = ((2 ^ 63) - 513) - (2 ^ 62) = 2 ^ 62 'False
Dim c5 As Boolean = ((2 ^ 63) - 1000) - (2 ^ 62) = 2 ^ 62 'False
Dim c6 As Boolean = ((2 ^ 63) - 10000) - (2 ^ 62) = 2 ^ 62 'False
Dim c7 As Boolean = ((2 ^ 63) - 100000) - (2 ^ 62) = 2 ^ 62 'False
Dim c8 As Boolean = ((2 ^ 63) - 1000000) - (2 ^ 62) = 2 ^ 62 'False

问题是:导致这种不准确的原因以及如何解决这个问题?

0 个答案:

没有答案