home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / LN.ZIP / LN.INC
Encoding:
Text File  |  1985-10-05  |  1.0 KB  |  33 lines

  1.  
  2. { ******************************************* }
  3. { *                                         * }
  4. { * The following is store as LN.INC        * }
  5. { *                                         * }
  6. { ******************************************* }
  7.  
  8.  
  9. { Turbo Pascal with BCD option does not support the ln function.          }
  10.  
  11. { This used the taylor series expansion about x=1 to approximate ln(x).   }
  12. { ln(x):=                                                                 }
  13. {   (1/1)*((x-1)^1) - (1/2)*((x-1)^2) + (1/3)*((x-1)^3) -                 }
  14. {   (1/4)*((x-1)^4) + .. - (1/(n-1))*((x-1)^(n-1)) + (1/n)*((x-1)^n) - .. }
  15.  
  16. { This expansion is valid for real values in the range 2>=x>0. }
  17.  
  18. function LN(X:real):real;
  19.   var WorkTotal:real;
  20.       term     :real;
  21.       i        :integer;
  22.   begin;
  23.     term:=x - 1;
  24.     WorkTotal:=term;
  25.     for i:=2 to 25 do
  26.       begin;
  27.         term:=term * (x - 1)*(-1) / i;
  28.         WorkTotal:=WorkTotal + term;
  29.       end;
  30.     ln:=WorkTotal;
  31.   end;
  32.  
  33.