Floating point less-than-equal comparisons after addition and substraction
Is there a "best practice" for less-than-equal comparisons with floating point number after a series of floating-point arithmetic operations? I have the following example in R (although the question applies to any language using floating-point). I have a double x = 1 on which I apply a series of additions and subtractions. In the end x should be exactly one but is not due to floating-point arithmetic (from what I gather). Here is the example: > stop_times <- seq(0.25, 2, by = .25) > expr <- expression(replicate(100,{ x <- 1 for(i in 1:10) { tmp <- rexp(1, 1) n <- sample.int(1e2, 1) delta <-