Post Reply 
Small RPN exponential routine
01-03-2015, 05:31 PM
Post: #4
RE: Small RPN exponential routine
This is my first attempt at natural logarithm using

ln(1 + x) = x - x^2/2 + x^3/3 - x^4/4 + x^5/5 -+ ..., x < 1

There surely is a more obvious method which I cannot see, so I won't bother optimizing it. I am primarily interested in implementing these functions on TurboBCD, but rather than trying to reinvent the wheel I'll look for a ready-made solution.

Code:

00 { 43-Byte Prgm }
01>LBL "LX"
02 NOT
03 +/-
04 LASTX
05 1
06 RCL- ST T
07 RCL÷ ST Z
08 LASTX
09 1
10>LBL 00
11 RCL÷ ST T
12 RCL+ ST Z
13 RCL× ST Y
14 STO ST Z
15 Rv
16 1
17 DSE ST T
18 GTO 00
19 RCL ST Z
20 +/-
21 .END.

0.52 ENTER 35 --> -6.53926467407e-1

There are two problems, though:

1) The series does not converge for arguments greater than 1;

2) More and more terms are required as arguments approach to zero. For instance, ln(0.052) will require 525 terms for 12-digit accuracy.

In these cases, conversions to and from decimal logarithms will help:


ln(0.52) = -6.53926467407e-1

2.30258509299 / --> -2.83996656366e-1

1 - 2.30258509299 * --> -2.95651156041 = ln(0.052)


ln(0.52) = -6.53926467407e-1

2.30258509299 / --> -2.83996656366e-1

1 + 2.30258509299 * --> 1.64865862558 = ln(5.2)


ln(0.52) = -6.53926467407e-1

2.30258509299 / --> -2.83996656366e-1

2 + 2.30258509299 * --> 3.95124371856 = ln(52)


ln(0.52) = -6.53926467407e-1

2.30258509299 / --> -2.83996656366e-1

3 + 2.30258509299 * --> 6.25382881155 = ln(520)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Small RPN exponential routine - Gerson W. Barbosa - 01-03-2015 05:31 PM
RE: Small RPN exponential routine - Namir - 01-21-2015, 12:34 AM
RE: Small RPN exponential routine - Namir - 01-20-2015, 09:24 PM
RE: Small RPN exponential routine - Namir - 01-22-2015, 08:41 AM
RE: Small RPN exponential routine - Namir - 01-23-2015, 05:11 PM



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