Displaying 2 results from an estimated 2 matches for "38589705".
2019 Feb 19
0
code for sum function
This SO question may be of interest:
https://stackoverflow.com/questions/38589705/difference-between-rs-sum-and-armadillos-accu/
which points out that sum() isn't doing anything fancy *except* using
extended-precision registers when available. (Using Kahan's algorithm
does come at a computational cost ...)
On 2019-02-19 2:08 p.m., William Dunlap via R-devel wrote:
&...
2019 Feb 19
4
code for sum function
The algorithm does make a differece. You can use Kahan's summation
algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) to
reduce the error compared to the naive summation algorithm. E.g., in R
code:
naiveSum <-
function(x) {
s <- 0.0
for(xi in x) s <- s + xi
s
}
kahanSum <- function (x)
{
s <- 0.0
c <- 0.0 # running compensation for lost