1

I happened to come across a question here that mentioned trying to assign a float to -0.0 or something along those lines. However, from what I have read so far negative zero is the same as positive zero, so why not just have zero? Why do the two exist?

4

1 回答 1

4

每个可能的浮点值实际上代表了一小部分可能的现实世界数字(因为可能的浮点数只有有限数量,但实际值的数量是无限的)。所以 0.0 表示介于 0.0 和非常小的正数之间的任何值,而 -0.0 表示介于 0.0 和非常小的负值之间的任何值。

但是请注意,当我们比较 0.0 和 -0.0 时,它们被认为是相等的,即使位的实际表示不同。

于 2013-09-08T10:20:06.263 回答