为什么浮点数已经签名为零? [英] Why do floating-point numbers have signed zeros?
问题描述
为什么双打有 -0
以及 +0
?什么是背景和意义?
以数学术语: 这说明 下面是一些相关的资源,已经提出了。为了完整起见,我已经包括了他们: Why do doubles have
If we consider the same case with a positive number, we will receive our good old
******* Here's a case where using
This makes sense if we consider the function (source) In math-terms: This illustrates one significant difference between Here are some relevant resources, some of which have been brought up already. I've included them for the sake of completeness: 这篇关于为什么浮点数已经签名为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 0
*******。当负数<!em>浮点数非常接近于零时,可能会导致它被认为是 0
(要清楚,我指的是来)
0
和<$ c $在计算意义上,c> -0 。
-0
as well as +0
? What is the background and significance?-0
is (generally) treated as 0
*******. It can result when a negative floating-point number is so close to zero that it can be considered 0
(to be clear, I'm referring to arithmetic underflow, and the results of the following computations are interpreted as being exactly ±0
, not just really small numbers). e.g.System.out.println(-1 / Float.POSITIVE_INFINITY);
-0.0
0
:System.out.println(1 / Float.POSITIVE_INFINITY);
0.0
-0.0
results in something different than when using 0.0
:System.out.println(1 / 0.0);
System.out.println(1 / -0.0);
Infinity
-Infinity
1 / x
. As x
approaches 0
from the +
-side, we should get positive infinity, but as it approaches from the -
-side, we should get negative infinity. The graph of the function should make this clear:0
and -0
in the computational sense.