通过将sqrt(-0.0)定义为-0.0来简化数值算法? [英] What numerical algorithm is simplified by defining sqrt(-0.0) as -0.0?
问题描述
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屋!