home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / EXP.ZIP / EXP.INC
Encoding:
Text File  |  1985-12-28  |  1.0 KB  |  32 lines

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