简体   繁体   English

为什么Gnu Octave具有负零?

[英]Why does Gnu Octave have negative zeroes?

This is an odd one I'm puzzled about. 这是我奇怪的一个奇怪的问题。 I recently noticed at the Gnu Octave prompt, it's possible to enter in negative zeroes, like so: 我最近在Gnu Octave提示中注意到,可以输入负零,如下所示:

octave:2> abomination = -0

And it remembers it, too: 它也记得它:

octave:3> abomination
abomination = -0

In the interest of sanity, negative zero does equal regular zero. 为了理智,负零等于正零。 But I also noticed that the sign has some other effects. 但我也注意到该标志还有其他作用。 Like these: 像这些:

octave:6> 4 * 0
ans = 0
octave:7> 4 * -0
ans = -0
octave:8> 4 / 0
warning: division by zero
ans = Inf
octave:9> 4 / -0
warning: division by zero
ans = -Inf

As one can see, the sign is preserved through certain operations. 可以看到,该标志通过某些操作得以保留。 But my question is why. 但是我的问题是为什么。 This seems like a radical departure from standard mathematics, where zero is essentially without sign. 这似乎与标准数学完全不同,在标准数学中,零基本上没有符号。 Are there some attractive mathematical properties for having this? 有一些吸引人的数学性质吗? Does this matter in certain fields of mathematics? 在某些数学领域这很重要吗?

FYI: Matlab, which octave is modeled after, does not have negative zeros. 仅供参考:以倍频建模的Matlab没有负零。 Any attempts to use them are treated as regular zeros. 任何使用它们的尝试都将被视为常规零。

EDIT: Matlab does have negative zeros, but they are not displayed in the default output. 编辑:Matlab确实有负零,但它们不会显示在默认输出中。

Signed zero are part of the IEEE-754 formats, and their semantics are completely specified by those formats. 带符号的零是IEEE-754格式的一部分,它们的语义完全由这些格式指定。 They turn out to be quite useful, especially when dealing with complex branch cuts and transformations of the complex plane (see many of W. Kahan's writings on the subject for more details, such as the classic "Branch Cuts for Complex Elementary Functions, or Much Ado about Nothing's Sign Bit"). 事实证明,它们非常有用,尤其是在处理复杂的分支切割和复杂平面的转换时(有关更多详细信息,请参阅W. Kahan关于该主题的许多著作,例如经典的《复杂基本功能的分支切割》或《知道什么都没有的迹象”。

Short version: negative zero is often a good thing to have in numerical calculations, and programs that try to protect users from encountering it are often doing them a disservice. 简短版:负零在数值计算中通常是一件好事,而试图保护用户免受其侵扰的程序通常会对他们造成伤害。 FWIW, MATLAB does seem to use negative zero as well, but since it prints numbers using the host's printf routine, they display the same as positive zero on Windows. FWIW,MATLAB似乎也使用负零,但是由于它使用主机的printf例程打印数字,因此它们在Windows上显示与正零相同。

See this discussion on the MATLAB forums for more details on signed zero in MATLAB. 有关MATLAB中有符号零的更多详细信息,请参见MATLAB论坛上的讨论

IEEE-754 floating point numbers have this property too. IEEE-754浮点数也具有此属性。 It might come in handy for limits and infinities. 对于限制和无限性可能会派上用场。 For example, the limit of 1/ x with x → +∞ is 0, but the function approaches from the positive side of the axis, with x → −∞ the function approaches from the negative side so one might give the limit as −0, in that case. 例如,极限的1 / x,其中x→+∞是0,但该功能从轴的正侧接近,其中x→-∞函数从负侧接近这样一个可能会给极限-0 , 在这种情况下。

Signed Zero 签名零

Signed zero echoes the mathematical analysis concept of approaching 0 from below as a one-sided limit, which may be denoted by x → 0−, x → 0−, or x → ↑0. 有符号的零呼应数学分析的概念,即从下面接近0作为一个单边极限,可以用x→0−,x→0−或x→↑0表示。 The notation "−0" may be used informally to denote a negative number that has been rounded to zero. 可以非正式地使用符号“ -0”来表示已舍入为零的负数。 The concept of negative zero also has some theoretical applications in statistical mechanics and other disciplines. 负零的概念在统计力学和其他学科中也有一些理论应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM