Natural logarithms

Logarithms with base e, where e is Euler's number, are called natural logarithms. We denote the natural logarithm of X by LN(X).

ALGORITHM
For 0<X<1 is LN(X)=-LN(1/X)
For X>1 find X=(2**M)*Z
Then

LN(X)=M*LN(2)-2*(Zeta/1+Zeta**3/3+Zeta**5/5+...)

IMPLEMENTATION
Unit: internal function, external function without procedure statement
 
Parameters: a real number X>0, a positive integer P - number of significant digits of LN(X), default is 9
 
Interface: LN2 function. For P<=200 we can use instead LN2Ponly the LN2 function
 
Returns: the first P significant decimal digits of LN(X)
 


LN: procedure
parse arg X, P
if P = "" then P = 9; numeric digits P
if X < 1 then return - LN(1 / X, P)
do M = 0 until (2 ** M) > X; end
M = M - 1
Z = X / (2 ** M)
Zeta = (1 - Z) / (1 + Z)
N = Zeta; Ln = Zeta; Zetasup2 = Zeta * Zeta
do J = 1
  N = N * Zetasup2; NewLn = Ln + N / (2 * J + 1)
  if NewLn = Ln then return M * LN2P(P) - 2 * Ln
  Ln = NewLn
end

 

 

LN2P: procedure
parse arg P
if P <= 200 then return LN2()
N = 1 / 3; Ln = N; Zetasup2 = 1 / 9
do J = 1
  N = N * Zetasup2; NewLn = Ln + N / (2 * J + 1)
  if NewLn = Ln then return 2 * Ln
  Ln = NewLn
end

 

CONNECTIONS

Literature
Jarník V. Diferenciální počet I
Nakladatelství České Akademie Věd, Praha, 1963


Cover Contents Index Main page Rexx page   Mail

last modified 1st August 2001
Copyright © 2000-2001 Vladimir Zabrodsky
Czech Republic