Post Reply 
RPN83P: RPN calculator for TI-83+ TI-84+ inspired by HP-42S
11-22-2023, 06:11 PM (This post was last modified: 11-22-2023 06:21 PM by bxparks.)
Post: #24
RE: RPN83P: RPN calculator for TI-83+ TI-84+ inspired by HP-42S
(11-22-2023 03:53 PM)Thomas Klemm Wrote:  I noticed the link while reading the source code of lnOnePlus in float.asm.

A few lines above we can find the following comment:
Quote: ; This uses ln(1+x) = x * log(1+x) / ((1+x)-1). I think this algorithm is
; faster than above, but apparently it doesn't work on certain computers
; (though I don't know why).
; See https://math.stackexchange.com/questions/175891

What do you mean exactly with "certain computers"?
Does it work with these TI calculators?
Otherwise, can you debug the code and maybe provide a trace of OP1, OP2 and FPS?

The "faster than above" is a slight typo, it should be "faster than below". I had flipped the order of the 2 implementations without updating the comments. The LOG1P_USING_LOG macro is now undefined by default, so the code selects the asinh() version. Hopefully that was clear from the context.

I have updated the comments, and added this new comment at the top of the function:

Quote:; Description: Calculate ln(1+x) such that it is less susceptible from
; cancellation errors when x is close to 0. By default the LOG1P_USING_LOG
; macro is not defined, so we end up with the hyperbolic asinh() version below.
; I prefer the asinh() version because I understand it. I could not follow the
; the explanation of why the LOG1P_USING_LOG version worked, or didn't work on
; certain environments.

So I think the x*ln(x)/((1+x)-1) *did* work for the TI calculators. But since I did not understand the explanation given in the math.stackexchange.com link about *why* it worked, I could not be sure that it worked for *all* ranges of numbers. The comment about not working on certain computers came from another source that has this formula, but I cannot remember what that other source was. (Maybe it was one of the old HP-15C or HP-34C solutions book.) Instead, I decided to use the asinh() version because I actually understand it. It's a mathematical identity, which I was able to re-derive. And as long as I used the expression which was less susceptible to numerical errors for x->0, that is log(1+x)=asinh((x/2)(1+1/(1+x))), I could depend on it. [Edit: Also added a stronger comment that the identity holds only for (1+x)>0, and this condition must be checked in the code. Because for (1+x)<0, the asinh() expression returns a value, but log(1+x) must throw an exception.]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: RPN83P: RPN calculator for TI-83+ TI-84+ inspired by HP-42S - bxparks - 11-22-2023 06:11 PM
Fat Man and Little Boy - gentzel - 11-06-2024, 09:29 PM



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