为什么Gnu Octave有零负? [英] Why does Gnu Octave have negative zeroes?

查看:300
本文介绍了为什么Gnu Octave有零负?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我很困惑的一个奇怪的。我最近注意到在Gnu Octave提示符下,可以输入零,如下所示:

  octave:2>憎恶= -0 

它也记得:

  octave:3>憎恶
憎恶= -0

为了理智,负零等于常零。但是我也注意到这个标志有其他一些效果。像这些:

  octave:6> 4 * 0 
ans = 0
八度:7> 4 * -0
ans = -0
八度:8> 4/0
警告:除以零
ans = Inf
八度:9> 4 / -0
警告:除以零
ans = -Inf

正如人们所看到的,这个标志是通过某些操作来保存的。但是我的问题是为什么。这似乎是一个从标准数学的根本背离,其中零基本上没有标志。有这样的一些有吸引力的数学属性吗?这在数学的某些领域是否有影响?



参考:Matlab,哪个八度音阶模拟,没有负零。任何尝试使用它们都被视为常规零。

编辑:
Matlab具有负的零,但它们不会显示在默认输出中。

p>

解决方案

有符号零是IEEE-754格式的一部分,它们的语义完全由这些格式指定。它们变得相当有用,特别是在处理复杂的分支切割和复杂平面的转换时(参见W. Kahan关于这个主题的许多着作的更多细节,比如经典的复杂基本函数的分支切割 )。

短版:在数值计算中,负零通常是一件好事,而试图保护用户免于遇到的程序是往往会对他们造成伤害。 FWIW,MATLAB似乎也使用负零,但是由于它使用主机的 printf 例程打印数字,它们在Windows上显示为正零。



关于MATLAB的这个讨论论坛上的更多细节,在MATLAB签名零。


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:

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. 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.

解决方案

Signed zero are part of the IEEE-754 formats, and their semantics are completely specified by those formats. 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").

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.

See this discussion on the MATLAB forums for more details on signed zero in MATLAB.

这篇关于为什么Gnu Octave有零负?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆