Kahan summation: Difference between revisions

m
→‎{{header|REXX}}: right justify numbers (A,B,C) if non-negative.
m (→‎{{header|REXX}}: add a comment to the REXX section header.)
m (→‎{{header|REXX}}: right justify numbers (A,B,C) if non-negative.)
Line 602:
show: procedure; parse arg a,b,c /*obtain the args.*/
say 'decimal digits =' digits() /*show # dec digs.*/
say ' a = ' left('', a>=0) a /*echo value ofshow A justified*/
say ' b = ' left('', b>=0) b /* " B " " B */
say ' c = ' left('', c>=0) c /* " C " " C */
say 'simple summation of a,b,c = ' (a+b)+c /*same as a+b+c */
say 'Kahan summation of a,b,c = ' kahan(a,b,c) /*sum via Kahan. */
say; say copies('▒',70); say /*display a fence.*/
return</lang>
Output note: &nbsp; This is a work in progress and attempts are being made to determine a suitable/workable epsilon.
 
'''output''' using PC/REXX and also Personal REXX:
<pre>
Line 615 ⟶ 617:
b = 3.14169
c = 2.71828
simple summation of a,b,c = 10005.8
Kahan summation of a,b,c = 10005.9
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
 
decimal digits = 30
a = 1.0
b = 0.00000000000000000000000000000315544362088404722164691426133
c = -0.00000000000000000000000000000315544362088404722164691426133
simple summation of a,b,c = 1.00000000000000000000000000000
Kahan summation of a,b,c = 1.00000000000000000000000000000
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
Line 632 ⟶ 634:
<pre>
decimal digits = 6
a = 10000.0
b = 3.14169
c = 2.71828
simple summation of a,b,c = 10005.8
Kahan summation of a,b,c = 10005.9
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
 
decimal digits = 30
a = 1.0
b = 0.00000000000000000000000000000315544362088404722164691426133
c = -0.00000000000000000000000000000315544362088404722164691426133
simple summation of a,b,c = 0.999999999999999999999999999997
Kahan summation of a,b,c = 1.00000000000000000000000000000
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
Line 652 ⟶ 654:
<pre>
decimal digits = 6
a = 10000.0
b = 3.14169
c = 2.71828
simple summation of a,b,c = 10005.8
Kahan summation of a,b,c = 10005.9
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
 
decimal digits = 30
a = 1.0
b = 3.15544362088404722164691426133E-30
c = -3.15544362088404722164691426133E-30
simple summation of a,b,c = 0.999999999999999999999999999997
Kahan summation of a,b,c = 1.00000000000000000000000000000
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
Line 672 ⟶ 674:
<pre>
decimal digits = 6
a = 10000.0
b = 3.14169
c = 2.71828
simple summation of a,b,c = 10005.8
Kahan summation of a,b,c = 10005.9
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
 
decimal digits = 30
a = 1.0
b = 3.15544362088404722164691426133E-30
c = -3.15544362088404722164691426133E-30
simple summation of a,b,c = 1.00000000000000000000000000000
Kahan summation of a,b,c = 1.00000000000000000000000000000
 
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒