[R] Bug or feature? sum(c(a, b, c)) != (a + b + c)

2011-08-23 Thread Daniel Lai
Greetings all, I'm porting an algorithm from MATLAB to R, and noticed some minor discrepancies in small decimal values using rowSums and colSums which are exacerbated after heavy iteration and log space transformation. This was rather perplexing as both programs claimed and appeared to use

Re: [R] Bug or feature? sum(c(a, b, c)) != (a + b + c)

2011-08-23 Thread Daniel Lai
Hi Barry, Shock and horror indeed, addition is not _associative_, at least for floating point arithmetic [1]. Flipping the order of the operands seems to be the explanation of the discrepancies between R and MATLAB as you suggest: In R: a = 0.812672 b = 0.916541 c = 0.797810