为什么 NA_real_ <= Inf return NA?

Why does NA_real_ <= Inf return NA?

在将 Inf-InfNA_real_ 进行比较时,returned 的某些值令我感到惊讶。

具体来说:

NA_real_ <= Inf
#[1] NA
-Inf <= NA_real_
#[1] NA

documentation for NA (help(NA)) 的第一句是

NA is a logical constant of length 1 which contains a missing value indicator.

我想一定有一些值不小于或等于Inf,一些值不大于或等于-Inf。这些价值观是什么?你如何在 R 中表示它们?请提供完整列表。

我对 NaN 有点熟悉,但这些不是由计算产生的结果超出 double 可以存储的适当值范围的结果吗?我不知道 Inf - Inf 到底是什么,但它不能大于 Inf。在 double 应该实施的 IEEE 标准中,有什么比 Inf 更大的?该标准是否简单地定义了任何涉及 NaN returns NaN 的操作?那为什么RreturnNaN不呢? NA 不是 IEEE 754 值,是吗?也许我误读了 documentation?

给你指出的地方是:

?Arithmetic
?Inf
?`>`

第一个表示一般使用IEEE 754:

R is dependent on OS services (and they on FPUs) for floating-point arithmetic. On all current R platforms IEC 60559 (also known as IEEE 754) arithmetic is used, but some things in those standards are optional. In particular, the support for denormal numbers (those outside the range given by .Machine) may differ between platforms and even between calculations on a single platform.

第二个表示无穷大的算术应该"work":

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

然而,第三个表示任何涉及NA returns NA:

的逻辑比较

Missing values (NA) and NaN values are regarded as non-comparable even to themselves, so comparisons involving them will always result in NA.

所以问题不在于某些东西 "larger" 比 Inf,而是当您调用带有缺失值的比较时 R returns 缺失值。