Kahan summation algorithm
|
12-19-2014, 09:12 PM
(This post was last modified: 12-19-2014 09:48 PM by Thomas Klemm.)
Post: #1
|
|||
|
|||
Kahan summation algorithm
For details please consult Wikipedia.
Program for the HP-42S: Code: 00 { 19-Byte Prgm } Worked example: \(10^{10}+\pi+e\) CLST E10 ENTER 0 PI XEQ "KAHAN" 1 E↑X R/S y: 10,000,000,005.9 x: -0.04012551795 This is the correctly rounded result. The classic addition is not the same: E10 PI + 1 E↑X + y: 0 x: 10,000,000,005.8 Cheers Thomas |
|||
12-20-2014, 09:47 AM
Post: #2
|
|||
|
|||
RE: Kahan summation algorithm
Thank you. Never seen this before.
|
|||
12-21-2014, 08:52 AM
Post: #3
|
|||
|
|||
RE: Kahan summation algorithm
What I have never seen mentioned is the fact that this algorithm is meant for binary floating point. Try adding x=y= 1e12-2
You'll get s := 2e12 c := -2, while it should be -4 BTW my version reads: Code: *LBL "K+" same size. Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)