I had an apparent bug in a script. After several hours, I discovered it was a problem of decimal approximations.
To make the problem reproducible, consider this:
0.02 - 0.000904686260609299 - 0.005 ==
0.02 + (-0.000904686260609299 - 0.005)
#[1] FALSE
Where:
print(0.02 -0.000904686260609299 -0.005, 22)
print(0.02 + (-0.000904686260609299 -0.005), 22)
#[1] 0.01409531373939069964774
#[1] 0.01409531373939070138246
Imagine a situation where you have long vectors a,b,c
:
a -b -c == a + (-b -c)
The difference might be statistically significant.
Can I increase the level of internal approximation so as to have the test above return TRUE
?
If I have to choice, which result is the best approximation:
a -b -c
or a + (-b -c)
?