A
asaguiar
Hi,
Given the pseudocode explanation of the Kahan algorithm at
http://en.wikipedia.org/wiki/Kahan_summation_algorithm, I tried to
implement it in C. It is supposed to minimize the effect of base
conversion errors after repeated sum operations.
However, the effect is null. The rounding error persists without
change.
My implementation is:
double kahanSum(double input, double tosum, double times)
{
double c=0.0, sum=input,y,t;
int count;
for(count=0; count<times; count++)
{
y=tosum-c;
t=sum+y;
c=(t-sum)-y;
sum=t;
}
return(sum);
}
Could you, please, point where I went wrong?
Thanks.
Alexandre Aguiar, MD
Given the pseudocode explanation of the Kahan algorithm at
http://en.wikipedia.org/wiki/Kahan_summation_algorithm, I tried to
implement it in C. It is supposed to minimize the effect of base
conversion errors after repeated sum operations.
However, the effect is null. The rounding error persists without
change.
My implementation is:
double kahanSum(double input, double tosum, double times)
{
double c=0.0, sum=input,y,t;
int count;
for(count=0; count<times; count++)
{
y=tosum-c;
t=sum+y;
c=(t-sum)-y;
sum=t;
}
return(sum);
}
Could you, please, point where I went wrong?
Thanks.
Alexandre Aguiar, MD