Kahan summation: Difference between revisions
Content added Content deleted
(Added an Algol 68 implementation) |
(GP -- partial) |
||
Line 356: | Line 356: | ||
See also http://keiapl.info/anec/#fuzz |
See also http://keiapl.info/anec/#fuzz |
||
=={{header|PARI/GP}}}== |
|||
No decimals here; the example below uses 64-bit binary arithmetic. |
|||
This is a ''partial solution'' only; I haven't found appropriate values that fail for normal addition. (Experimentation should produce these, in which case the existing code should work with the inputs changed.) |
|||
<lang parigp>Kahan(v)=my(s=0.,c=0.,y,t);for(i=1,#v,y=v[i]-c;t=s+y;c=t-s-y;s=t);s; |
|||
epsilon()=my(e=1.); while(e+1. != 1., e>>=1); e; |
|||
\p 19 |
|||
e=epsilon(); |
|||
Kahan([1.,e,-e])</lang> |
|||
{{out}} |
|||
<pre>%1 = 1.000000000000000000</pre> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |