通过将sqrt(-0.0)定义为-0.0来简化数值算法? [英] What numerical algorithm is simplified by defining sqrt(-0.0) as -0.0?

查看:134
本文介绍了通过将sqrt(-0.0)定义为-0.0来简化数值算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IEEE 754标准定义负零的平方根为负零。这个选择很容易理解,但是其他选择,比如定义 sqrt(-0.0) NaN ,可以也要合理化,并且在硬件上更容易实现。如果担心程序员会编写 if(x> = 0.0),那么sqrt(x)else 0.0 并被这个表达式咬住,计算结果为 x -0.0 ,那么 sqrt( - 0.0)可以被定义为 +0.0 (实际上,对于这个特定的表达式,结果会更加一致)。



是否有一个数值算法,其中 sqrt(-0.0)定义为 -0.0 简化了算法本身的逻辑?

解决方案

唯一的数学上合理的结果是0.有一个合理的问题应该是+0还是-0。对于大多数计算来说,它根本没有什么区别,但是在-0约定下,有一些特定的复杂表达式使得结果更有意义。确切的细节超出了本网站的范围,但这是它的要义。



当我不在度假时,我可以解释一些,如果其他人我不会打我的。


The IEEE 754 standard defines the square root of negative zero as negative zero. This choice is easy enough to rationalize, but other choices, such as defining sqrt(-0.0) as NaN, can be rationalized too and are easier to implement in hardware. If the fear was that programmers would write if (x >= 0.0) then sqrt(x) else 0.0 and be bitten by this expression evaluating to NaN when x is -0.0, then sqrt(-0.0) could have been defined as +0.0 (actually, for this particular expression, the results would be even more consistent).

Is there a numerical algorithm in particular where having sqrt(-0.0) defined as -0.0 simplifies the logic of the algorithm itself?

解决方案

The only mathematically reasonable result is 0. There is a reasonable question of whether it should be +0 or -0. For most computations it makes no difference at all, but there are some specific complex expressions for which the result makes more sense under the -0 convention. The exact details are outside the scope of this site, but that's the gist of it.

I may explain some more when I'm not on vacation, if someone else doesn't beat me to it.

这篇关于通过将sqrt(-0.0)定义为-0.0来简化数值算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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