home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 164_01 / tran.c < prev    next >
Text File  |  1984-04-08  |  1KB  |  75 lines

  1. /* Transcendental function library */
  2. #define E 2.718281828
  3.  
  4. /* Square root of x */
  5. double root(x)
  6. double x;
  7. {
  8. double a, x1, x2=1;
  9. x1 = x;
  10. if (x > 0) {
  11. while (x2 > .00000001) {
  12.     a = x;
  13.     x = x1 / a + a;
  14.     x = x / 2;
  15.     if (x >= a) x2=x-a;
  16.     else x2=a-x;
  17.     }
  18. }
  19. else x=0;
  20. return (x);
  21. }
  22.  
  23. /* Logarithm of x */
  24. double log(x)
  25. double x;
  26. {
  27. double a=0, x1, x2=0, x3=1;
  28. int t;
  29.     if (x>0) {
  30.     x1 = x;
  31.     for (t=0; x1<.5; t--)
  32.         x1 *= E;
  33.     for (t=t; x1>1.5; t++)
  34.         x1 /= E;
  35.     a = t;
  36.     x1 = x1-1;
  37.     x  = -x1;
  38.     for (t=1; x3>.0000001; t++) {
  39.         x2 = x1/t;
  40.         a = a + x2;
  41.         x1 = x1 * x;
  42.         x3 = (x2>=0) ? x2 : -x2;
  43.     }
  44.     }
  45. return (a);
  46. }
  47.  
  48. /* Exponential of x */
  49. double exp(x)
  50. double x;
  51. {
  52. double a, x1, x2, x3, x4, x7=1;
  53. int x5, x6, t;
  54.     if (x5=(x<0)) x=-x;
  55.     t  = x;
  56.     x4 = 1;
  57.     x = x-t;
  58.     for (x6 = 1; x6 <= t; x6++)
  59.         x4 *= E;
  60.     x1=x;
  61.     x=1;
  62.     x2=x1;
  63.     x3=0;
  64.     for (x6=2; x7>.0000001; x6++) {
  65.         x=x+x2;
  66.         x2=x2*x1/x6;
  67.         x7 = (x2 >= 0) ? x2 : -x2;
  68.     }
  69.     x = x*x4;
  70.     return (x5 ? 1/x : x);
  71. }
  72. }for (x6=2; x7>.0000001; x6++) {
  73.         x=x+x2;
  74.         x2=x2*x1/x6;
  75.         x7 = (x2 >= 0) ? x2