Skip to contents

These functions compare values while accounting for differences in floating point precision.

Usage

compareFloat(x, y, op, tol = .Machine$double.eps^0.5)

x %<% y

x %<=% y

x %==% y

x %>=% y

x %>% y

x %!=% y

Arguments

x, y

Numeric

op

Operator for comparison (must be in quotes): "<", ">", "<=", ">=", "==", or "!="

tol

Tolerance value: The largest absolute difference between x and y that is to be considered equality. The default is .Machine$double.eps^0.5.

Value

TRUE, FALSE, or NA

Examples

x <- 0.9 - 0.8
y <- 0.8 - 0.7

x < y
#> [1] TRUE
x %<% y
#> [1] FALSE
compareFloat(x, y, "<")
#> [1] FALSE

x <= y
#> [1] TRUE
x %<=% y
#> [1] TRUE
compareFloat(x, y, "<=")
#> [1] TRUE

x == y
#> [1] FALSE
x %==% y
#> [1] TRUE
compareFloat(x, y, "==")
#> [1] TRUE

y > x
#> [1] TRUE
y %>% x
#> [1] FALSE
compareFloat(y, x, ">")
#> [1] FALSE

y >= x
#> [1] TRUE
y %>=% x
#> [1] TRUE
compareFloat(y, x, ">=")
#> [1] TRUE

x != y
#> [1] TRUE
x %!=% y
#> [1] FALSE
compareFloat(x, y, "!=")
#> [1] FALSE