为什么NaN ^ 0 == 1 [英] Why does NaN^0 == 1

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

问题描述

早期打高尔夫球的原因提示为什么:

Prompted by a spot of earlier code golfing why would:

>NaN^0
[1] 1

NA^0设为1完全有意义,因为NA缺少数据,并且 any 的数字升为0会得到1,包括-InfInf.但是NaN应该表示一个数字,那么为什么会这样呢?当?NaN的帮助页面指出:

It makes perfect sense for NA^0 to be 1 because NA is missing data, and any number raised to 0 will give 1, including -Inf and Inf. However NaN is supposed to represent not-a-number, so why would this be so? This is even more confusing/worrying when the help page for ?NaN states:

在R中,基本上所有数学函数(包括基本 算术),应该可以与+/- Inf和NaN一起正常工作 输入或输出.

In R, basically all mathematical functions (including basic Arithmetic), are supposed to work properly with +/- Inf and NaN as input or output.

基本规则应该是与Infs的通话和联系确实是 有适当数学限制的陈述.

The basic rule should be that calls and relations with Infs really are statements with a proper mathematical limit.

涉及NaN的计算将返回NaN或可能返回NA : 这两个不能保证,可能取决于R平台(因为 编译器可能会重新排序计算.)

Computations involving NaN will return NaN or perhaps NA: which of those two is not guaranteed and may depend on the R platform (since compilers may re-order computations).

这背后是否存在哲学上的原因,还是与R代表这些常数的方式有关?

Is there a philosophical reason behind this, or is it just to do with how R represents these constants?

推荐答案

?'NaN'

"IEC 60559标准,也称为ANSI/IEEE 754浮点标准.

"The IEC 60559 standard, also known as the ANSI/IEEE 754 Floating-Point Standard.

http://en.wikipedia.org/wiki/NaN ."

您会发现以下有关应创建NaN的声明:

And there you find this statement regarding what should create a NaN:

 "There are three kinds of operations that can return NaN:[5]
       Operations with a NaN as at least one operand.

它可能来自特定的C编译器,如您所引用的Note所示.这就是GNU C文档所说的:

It is probably is from the particular C compiler, as signified by the Note you referenced. This is what the GNU C documentation says:

http://www.gnu.org/software/libc/manual /html_node/Infinity-and-NaN.html

另一方面,NaN会感染涉及该计算的任何计算.除非该计算将产生相同的结果,无论用什么实际值替代NaN,否则结果均为NaN."

" NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN."

因此,看起来GNU-C人们在编写代码时会想到不同的标准.据报道,2008年版的ANSI/IEEE 754浮点标准提出了这一建议:

So it seems that the GNU-C people have a different standard in mind when writing their code. And the 2008 version of ANSI/IEEE 754 Floating-Point Standard is reported to make that suggestion:

http://en.wikipedia.org/wiki/NaN#Function_definition

发布的标准不是免费的.因此,如果您具有访问权限或金钱,可以在这里查看:

The published standard is not free. So if you are have access rights or money you can look here:

http://ieeexplore.ieee.org/xpl/mostRecentIssue.jsp?punumber=4610933

这篇关于为什么NaN ^ 0 == 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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