Anonymous user
Kahan summation: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace.
(Implementation in Crystal) |
m (→{{header|REXX}}: added/changed whitespace.) |
||
Line 1,919:
call show 10000.0, 3.14169, 2.71828 /*invoke SHOW to sum & display numbers.*/
numeric digits 30 /*from now on, use 30 decimal digits.*/
epsilon= 1
do while 1+epsilon \= 1 /*keep looping 'til we can't add unity.*/
epsilon= epsilon / 2
end /*while*/
say /*display a blank line before the fence*/
Line 1,928:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
kahan: procedure; $= 0; c= 0; do j=1 for arg()
end /*j*/
return $
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: procedure; parse arg a,b,c /*obtain the arguments. */
say 'decimal digits =' digits() /*show number of decimal digs*/
say ' a = ' left(
say ' b = ' left(
say ' c = ' left(
say 'simple summation of a,b,c = ' a+ b+
say 'Kahan summation of a,b,c = ' kahan(a, b, c)
return</lang>
{{out|output|text= using PC/REXX and also Personal REXX:}}
Line 2,017:
call show 10000.0, 3.14169, 2.71828 /*invoke SHOW to sum & display numbers.*/
numeric digits 30 /*from now on, use 30 decimal digits.*/
epsilon= 1
do while 1+epsilon \= 1 /*keep looping 'til we can't add unity.*/
epsilon= epsilon / 2
end /*while*/
say /*display a blank line before the fence*/
Line 2,028:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
kahan: procedure; $= 0; c= 0; do j=1 for arg()
end /*j*/
return $
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: procedure; parse arg a,b,c /*obtain the arguments. */
say 'decimal digits =' digits() /*show number of decimal digs*/
say ' a = ' left(
say ' b = ' left(
say ' c = ' left(
say 'simple summation of a,b,c = ' a+ b+
say 'Kahan summation of a,b,c = ' kahan(a, b, c)
return</lang>
{{out|output|text= using Regina version 3.4 and also for later versions:}}
Line 2,060:
simple summation of a,b,c = 1.0000000000000000000000000000001
Kahan summation of a,b,c = 1.0000000000000000000000000000000</pre>
</pre>
=={{header|Ruby}}==
|