Skip to contents

Test if x is zero. This is done by checking if the numeric value is below the machine tolerance.

Usage

isZero(x, tol = sqrt(.Machine$double.eps), na.rm = FALSE)

Arguments

x

a (non-empty) numeric or complex vector of data values.

tol

tolerance to be used.

na.rm

logical, indicating whether NA values should be stripped before the computation proceeds. Defaults to FALSE.

Value

logical vector of the same length as x (after optional NA removal). Non-numeric input yields all-FALSE.

References

Burns, P. (2011). The R Inferno. https://www.burns-stat.com/documents/books/the-r-inferno/

Examples

# "... These are people who live in ignorance of the Floating Point Gods.
# These pagans expect [...] the following to be TRUE" (Burns, 2011):
(.1 - .3 / 3) == 0
#> [1] FALSE

# they might be helped by
isZero(.1 - .3 / 3)
#> [1] TRUE