Kahan summation: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added "version"s to various output sections.) |
|||
Line 1,762: | Line 1,762: | ||
Kahan summation of a,b,c = 1.00000000000000000000000000000 |
Kahan summation of a,b,c = 1.00000000000000000000000000000 |
||
</pre> |
</pre> |
||
{{out|output|text= using Regina 3.3 and earlier:}} |
{{out|output|text= using Regina version 3.3 and earlier:}} |
||
<pre> |
<pre> |
||
decimal digits = 6 |
decimal digits = 6 |
||
Line 1,779: | Line 1,779: | ||
simple summation of a,b,c = 0.999999999999999999999999999997 |
simple summation of a,b,c = 0.999999999999999999999999999997 |
||
Kahan summation of a,b,c = 1.00000000000000000000000000000</pre> |
Kahan summation of a,b,c = 1.00000000000000000000000000000</pre> |
||
{{out|output|text= using Regina 3.4 and later (latest at this time is 3.9.1):}} |
{{out|output|text= using Regina version 3.4 and later (latest at this time is version 3.9.1):}} |
||
<pre>decimal digits = 6 |
<pre>decimal digits = 6 |
||
a = 10000.0 |
a = 10000.0 |
||
Line 1,797: | Line 1,797: | ||
===tweaked version=== |
===tweaked version=== |
||
The following tweaked REXX version causes Regina (3.4 and later) to work properly. |
The following tweaked REXX version causes Regina (version 3.4 and later) to work properly. |
||
<lang rexx>/*REXX program demonstrates simple addition versus using Kahan summation algorithm. */ |
<lang rexx>/*REXX program demonstrates simple addition versus using Kahan summation algorithm. */ |
||
numeric digits 6 /*use six decimal digits for precision.*/ |
numeric digits 6 /*use six decimal digits for precision.*/ |
||
Line 1,829: | Line 1,829: | ||
say 'Kahan summation of a,b,c = ' kahan(a,b,c) /*sum via Kahan summation. */ |
say 'Kahan summation of a,b,c = ' kahan(a,b,c) /*sum via Kahan summation. */ |
||
return</lang> |
return</lang> |
||
{{out|output|text= using Regina 3.4 and also for later versions:}} |
{{out|output|text= using Regina version 3.4 and also for later versions:}} |
||
<pre>decimal digits = 6 |
<pre>decimal digits = 6 |
||
a = 10000.0 |
a = 10000.0 |
||
Line 1,845: | Line 1,845: | ||
simple summation of a,b,c = 1.0000000000000000000000000000001 |
simple summation of a,b,c = 1.0000000000000000000000000000001 |
||
Kahan summation of a,b,c = 1.0000000000000000000000000000000</pre> |
Kahan summation of a,b,c = 1.0000000000000000000000000000000</pre> |
||
'''output''' for ooRexx: |
'''output''' for ooRexx: |
||
<pre>decimal digits = 6 |
<pre>decimal digits = 6 |
||
Line 1,863: | Line 1,864: | ||
ªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªª</pre> |
ªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªªª</pre> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
===IEEE 754 Single precision 32-bit (JavaScript defaults to Double precision.)=== |
===IEEE 754 Single precision 32-bit (JavaScript defaults to Double precision.)=== |