I found a interesting bug in R and replicated it on different machines in different versions of R.
If I take the 2nd modulo of 14 (14 %% 2
), I expect 0
as result. This works fine:
> 14 %% 2
[0] 0
If I take the 2nd modulo of (100 * 0.14)
, which is 14 obviously, I get 1.776357e-15
as a result.
> (100 * 0.14) %% 2
[0] 1.776357e-15
I investigated a bit and found, that this only happens for (14 * n²):
> (100 * 0.14) %% 2
[0] 1.776357e-15
> (100 * 0.28) %% 2
[0] 3.552714e-15
> (100 * 0.54) %% 2
[0] 7.105427e-15
Does someone has an explanation for this behaviour?