In R, why is this false for y > 2?
y <- c(1, 2, 3, 4, 5)
x <- 2*y
exp(log(x)) == exp(log(y)) * 2
[1] TRUE TRUE FALSE FALSE FALSE
In R, why is this false for y > 2?
y <- c(1, 2, 3, 4, 5)
x <- 2*y
exp(log(x)) == exp(log(y)) * 2
[1] TRUE TRUE FALSE FALSE FALSE
Numeric precision. Try calculating the difference:
exp(log(x)) - exp(log(y)) * 2
You could use something like:
all.equal( exp(log(x)) , exp(log(y)) * 2 )
Exactly, the numerci precision is the cause. Try this, even simpler calculation
1/2+1/3+1/6 #equal to 1
(1/2+1/3+1/6)-1 # should be 0
[1] -1.110223e-16