Kahan summation: Difference between revisions

Add Factor
m (→‎tweaked version: elided an extra </pre> HTML tag.)
(Add Factor)
Line 496:
Sum: 1.000000e+000
Kahan: 1.000000e+000</pre>
 
=={{header|Factor}}==
Factor's floats use IEEE 754 double-precision format. Note the <code>kahan-sum</code> word already exists in Factor's standard library (in the <code>math.extras</code> vocabulary). See the implementation [https://docs.factorcode.org/content/word-kahan-sum%2Cmath.extras.html here].
{{works with|Factor|0.99 2019-10-06}}
<lang factor>USING: io kernel literals math math.extras prettyprint sequences ;
 
: epsilon ( -- x ) 1.0 [ dup 1 + 1 number= ] [ 2 /f ] until ;
 
${ 1.0 epsilon dup neg }
[ "Left associative: " write sum . ]
[ "Kahan summation: " write kahan-sum . ] bi
"Epsilon: " write epsilon .</lang>
{{out}}
<pre>
Left associative: 0.9999999999999999
Kahan summation: 1.0
Epsilon: 1.110223024625157e-16
</pre>
 
=={{header|Fortran}}==
1,808

edits