What is a robust and concise way to make less <
and greater >
comparisons that are robust to floating-point imprecision, i.e., operations that are robust to small differences that could stem from floating-point inaccuracy issues?
In other terms: For ==
we have all.equal
, but what do we have for <
and >
?
Tidyverse example with tibble
library(tidyverse)
tribble(~ x, 0.1 + 0.2) %>%
mutate(
test = x > 0.3
)
results in
# A tibble: 1 × 2
x test
<dbl> <lgl>
1 0.3 TRUE
whereas I would expect FALSE
instead of TRUE
(since 0.3 > 0.3 mathematically is false).