尽管 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
Run Code Online (Sandbox Code Playgroud)