R有“负零”吗?
我的控制台告诉我,-0回报0和这两个c(1:5)[0]和c(1:5)[-0]回报integer(0)。R 这是否意味着 R 没有“负零”的概念?
回答
尽管 R 很好地隐藏了它,但实际上 R 确实有一个负零:
# R says these are the same
0 == -0
## [1] TRUE
identical(0, -0)
## [1] TRUE
# but they are not
is.neg0 <- function(x) x == 0 && sign(1/x) == -1
is.neg0(0)
## [1] FALSE
is.neg0(-0)
## [1] TRUE