Computation of natural logarithms by AG means


function ln ( x : number ) : number; var a, b, temp : number; shift, logbase : integer; begin logbase := crude_estimate_of_ln(x)/ln(BASE); if 2*logbase<Digits then begin shift := Digits div 2 - logbase + 1; ln := ln( x * BASE**shift ) - shift*LNBASE end else begin a := 1.0; b := 4/x; while a-b>sqrteps do begin temp := a; a := (a+b) / 2; b := sqrt( temp*b ) end; ln := Pi / (a+b) end end;

Pascal source (623.ln.p)



© Addison-Wesley Publishing Co. Inc.