A (quite) accurate ln1+x function, or "how close can you get" part II
|
04-09-2014, 06:44 PM
(This post was last modified: 04-09-2014 07:28 PM by Dieter.)
Post: #1
|
|||
|
|||
A (quite) accurate ln1+x function, or "how close can you get" part II
Over the last days there has been some discussion regarding the accurate evaluation of the TVM equation. For small interest rates a dedicated ln1+x function allows significantly better accuracy than the standard method. But such a function is missing on many calculators, as well as its counterpart, a special ex–1 function.
There have been some suggestions on how to emulate a sufficiently accurate ln1+x function on calculators that do not offer one in their function set. On the one hand there is the widely know classic approach as suggested by W. Kahan in the HP-15C Advanced Functions Handbook, on the other hand some other ways based on hyperbolic functions have been suggested, both for ln1+x and ex–1. I did some accuracy tests with these methods, the results have been posted in another thread. Among 100.000 random numbers between 1 and 10–15 these methods showed errors of about 5...9 units in the last place. I wanted to know if this can be improved, so I tried a new approach. It does not require any exotic hyperbolics and is based on a Taylor series: Let \(u = 1+x\) rounded Then \(ln(1+x) \simeq ln u - \frac{(u-1) - x}{u}\) I did a test with this method, using the WP34s emulator with 16 digit standard precision. The following program was used to generate 100.000 random numbers between 1 and 10–16. Dependig on Flag A, either the classic HP/Kahan method (Flag A set) or the new method (Flag A clear) is used. Code: 001 LBL D And here are the results: Select HP/Kahan method: f [SF] [A] The = symbol appears Start: [D] "Running PrOGrAM"... Result in x and y: largest positive error: +8 ULP largest negative error: –5 ULP This matches the error level reported earlier. Now let's see how the new method compares: Select new method: g [CF] [A] The = symbol disappears Start: [D] "Running PrOGrAM"... Result in x and y: largest positive error: +2 ULP largest negative error: –1 ULP That looks much better. Further tests showed the following error distribution: –2 ULP: 0 –1 ULP: 10553 ±0 ULP: 74440 +1 ULP: 14996 +2 ULP: 11 Edit: Another run with 1 milliion random numbers shows the same pattern: –2 ULP: 0 –1 ULP: 105163 ±0 ULP: 744963 +1 ULP: 149766 +2 ULP: 108 So nearly 99,99% of the results are within ±1 ULP. What do you think? Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
A (quite) accurate ln1+x function, or "how close can you get" part II - Dieter - 04-09-2014 06:44 PM
RE: A (quite) accurate ln1+x function, or "how close can you get" part II - htom trites - 04-10-2014, 04:47 AM
RE: A (quite) accurate ln1+x function, or "how close can you get" part II - Dieter - 04-11-2014, 07:01 PM
RE: A (quite) accurate ln1+x function, or "how close can you get" part II - Albert Chan - 01-31-2019, 07:04 PM
RE: A (quite) accurate ln1+x function, or "how close can you get" part II - Albert Chan - 02-01-2019, 04:26 PM
|
User(s) browsing this thread: 3 Guest(s)