# R precision in operations [closed]

If you try to calculate the difference between (9.1 - 8.9) - (6.9-6.7) in R, you'll get

> (9.1 - 8.9) - (6.9-6.7)
[1] -8.881784e-16


I found this when I was trying to calculate ranks considering ties as average rank but I saw that because of precision issue, it don't consider the tie.

A <- c( 6.1, 5.5, 8.9, 7.4, 4.3, 9.7, 6.7, 9.4)
B <- c( 7.3, 5.5, 9.1, 7.0, 5.1, 9.8, 6.9, 9.8)
Z <- B - A
rank(abs(Z))
[1] 8.0 1.0 3.0 5.5 7.0 2.0 4.0 5.5


Expected result

[1] 8.0 1.0 3.5 5.5 7.0 2.0 3.5 5.5


> A <- c( 6.1, 5.5, 8.9, 7.4, 4.3, 9.7, 6.7, 9.4)