Displaying 1 result from an estimated 1 matches for "b800000000001p".
2010 Jun 24
5
Best way to compute a sum
> a <- 0 ; for(i in (1:200000000)) a <- a + 1/i
> b <- 0 ; for(i in (200000000:1)) b <- b + 1/i
> c <- sum(1/(1:200000000))
> d <- sum(1/(200000000:1))
> order(c(a,b,c,d))
[1] 1 2 4 3
> b<c
[1] TRUE
> c==d
[1] FALSE
I'd expected b being the largest, since we sum up the smallest
numbers first. Instead, c is the largest, which is