Post Reply 
Calculating e^x-1 on classic HPs
01-14-2016, 01:48 PM (This post was last modified: 01-14-2016 02:53 PM by Dieter.)
Post: #15
RE: Calculating e^x-1 on classic HPs
(01-14-2016 07:20 AM)Paul Dale Wrote:  
Code:
    u = e^x
    v = u - 1
    if v = 0, return x
    if v = -1, return -1
    return v * x / ln(u)

As William Kahan said of this: nearly full working relative accuracy despite cancellation no matter how tiny x may be.

Ah, interesting. I have been looking for an equivalent to Kahan's ln(1+x) method, but I could not find anything. Where is this documented? Or is this "Dale's method" ?-)

Adding another test (before the other two) may speed up the code as it avoids the log in the last line:
Code:
    if v >= 1, return v
This may lead to an error in the last place for arguments where e^x = 10...11, 100...101, 1000...1001 etc. Here the last digit is lost. But this may also occur with the unchanged method:

I did a few test runs on a 34s in SP mode with 100000 random numbers each. About 45% were exact, and another 45% was within ±1 ULP. Another 9% was ±2 ULP and the rest had larger errors. So accuracy varies a bit more than with the method I suggested (90% vs. 99,5% within ±1 ULP).

Note: I originally posted that the results using your method were at most –1 ULP off. Sorry, this is wrong, there was an error in the test routine. #-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Calculating e^x-1 on classic HPs - Dieter - 01-11-2016, 10:20 PM
RE: Calculating e^x-1 on classic HPs - Dieter - 01-14-2016 01:48 PM



User(s) browsing this thread: 13 Guest(s)