Possible Duplicate:
Why are these numbers not equal?
in Gnu R:
which(seq(0, 1600, 0.05) == 0.3) returns
integer(0)
but this:
which(round(seq(0, 1600, 0.05),2) == 0.3) returns
[1] 7
What happens with the seq()
function?
Possible Duplicate:
Why are these numbers not equal?
in Gnu R:
which(seq(0, 1600, 0.05) == 0.3) returns
integer(0)
but this:
which(round(seq(0, 1600, 0.05),2) == 0.3) returns
[1] 7
What happens with the seq()
function?
That is essentially R FAQ 7.31 on comparisons between floats -- leading to the famous 'What every Computer Scientist should know about floating point numbers'.
In a nutshell, use identical()
and other helper functions to compare relative to a small value \epsilon as perfect equality cannot be had with floating point types.