【发布时间】:2019-10-09 20:17:56
【问题描述】:
(添加了可重现的示例)
我无法理解为什么以下是FALSE(我知道它们分别是double 和integer):
identical(1, as.integer(1)) # FALSE
?identical 透露:
num.eq: 逻辑指示是否应该使用 == ('equal') 或按位比较来比较(双精度和非 NA 复数)数字。后者(非默认) 区分 -0 和 +0。
sprintf("%.8190f", as.integer(1)) 和 sprintf("%.8190f", 1) 返回完全相等位模式。所以,我认为以下至少一项必须返回TRUE。但是,我在以下各项中都得到了FALSE:
identical(1, as.integer(1), num.eq=TRUE) # FALSE
identical(1, as.integer(1), num.eq=FALSE) # FALSE
我现在这样考虑:如果sprintf 是符号指示符,而不是存储指示符,那么这意味着identical() 基于存储进行比较。 IE。
identical(bitpattern1, bitpattern1bitpattern2) 返回FALSE。对于上述FALSE/FALSE情况,我找不到任何其他合乎逻辑的解释。
我知道在 R 的 32 位/64 位架构中,整数都存储为 32 位。
【问题讨论】:
-
identical(1, as.numeric("1"))产生TRUE。这可能是一个起点。另外,identical(1L, as.integer("1"))也是TRUE -
@Kots 在两个相同的(...)中,您正在比较相同的东西:“double1 vs double1”和“integer1 vs integer1”。在我的问题中,比较了“double1 vs integer1”。
-
那我猜你有答案了
标签: r integer double storage notation