Examples for 'R.utils::isZero.default'


Checks if a value is (close to) zero or not

Aliases: isZero.default isZero

Keywords: logic

### ** Examples

x <- 0
print(x == 0)      # TRUE
[1] TRUE
print(isZero(x))   # TRUE
[1] TRUE
x <- 1
print(x == 0)      # FALSE
[1] FALSE
print(isZero(x))   # FALSE
[1] FALSE
x <- .Machine$double.eps
print(x == 0)      # FALSE
[1] FALSE
print(isZero(x))   # FALSE
[1] FALSE
x <- 0.9*.Machine$double.eps
print(x == 0)      # FALSE
[1] FALSE
print(isZero(x))   # TRUE
[1] TRUE
# From help(Comparisions)
x1 <- 0.5 - 0.3
x2 <- 0.3 - 0.1
print(x1 - x2)
[1] 2.775558e-17
print(x1 == x2)                           # FALSE on most machines
[1] FALSE
print(identical(all.equal(x1, x2), TRUE)) # TRUE everywhere
[1] TRUE
print(isZero(x1-x2))                      # TRUE everywhere
[1] TRUE

[Package R.utils version 2.11.0 Index]