Kahan summation: Difference between revisions

Added 11l
(Kahan summation en Yabasic)
(Added 11l)
Line 36:
* All examples should have constants chosen to clearly show the benefit of Kahan summing!
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F kahansum(input)
V summ = 0.0s
V c = 0.0s
L(num) input
V y = num - c
V t = summ + y
c = (t - summ) - y
summ = t
R summ
 
V eps = 1.0s
L 1.0s + eps != 1.0s
eps = eps / 2.0s
 
print(‘Epsilon = ’eps)
print(‘(a + b) + c = #.7’.format((1.0s + eps) - eps))
print(‘Kahan sum = #.7’.format(kahansum([1.0s, eps, -eps])))</lang>
 
{{out}}
<pre>
Epsilon = 5.960464e-8
(a + b) + c = 0.9999999
Kahan sum = 1.0000000
</pre>
 
=={{header|ALGOL 68}}==
1,481

edits