Can anyone explain the following:
> any(seq(from=-10.1,to=10.1,by=0.1)==0)
[1] FALSE
> any(seq(from=-1.1,to=1.1,by=0.1)==0)
[1] TRUE
This confuses me a lot. It has probably something to do with floating point precision in R, but I am not able to wrap my head around it.
If you print the sequences, in the first case 0 is represented as 0
and in the second it's 1.776357e-15
. But why is the switch from 1.1 to 10.1 invoking this behaviour. Both numbers are float anyway. right?