home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff274.lzh / HP11 / support.c < prev    next >
C/C++ Source or Header  |  1989-11-16  |  2KB  |  140 lines

  1. #include "math.h"
  2.  
  3. #include "hp11/support.h"
  4.  
  5. double sign(r)
  6. double r;
  7. {
  8.    if (r < 0.0) return(-1.0);
  9.    else if (r == 0.0) return (0.0);
  10.    else return(1.0);
  11. }
  12.  
  13. void Rect(r, phi, x, y)
  14. double r, phi, *x, *y;
  15. {
  16.    *x = r * cos(phi);
  17.    *y = r * sin(phi);
  18. }
  19.  
  20. void Polar(x, y, r, phi)
  21. double x, y, *r, *phi;
  22. {
  23.    *r = sqrt(x * x + y * y);
  24.    *phi = atan2(y, x);
  25. }
  26.  
  27. double stirling(n)
  28. double n;
  29. {
  30.    double y = 1 / (12 * n);
  31.  
  32.    return (pow(n / E, n) * sqrt(2 * PI * n) * (1 + y * (1 + y * (0.5 - y * (4.6333333333333333 + y * 4.7583333333333333)))));
  33. }
  34.  
  35. double gamma(x)
  36. double x;
  37. {
  38.    double fx, tx, res, i;
  39.  
  40.    if (x >= 15.0) return(stirling(x - 1));
  41.    else {
  42.       if ((fx = modf(x, &tx)) < 0) { tx -= 1.0; fx += 1.0; } /* give real int & frac */
  43.  
  44.       if (fx == 0 && tx < 0) return(-HUGE);
  45.       if (tx < -200) return(0.0); /* Underflow */
  46.  
  47.       res = stirling(fx + 14.0);
  48.       for (i = 14.0; i >= tx; i -= 1.0) res /= i + fx;
  49.  
  50.       return(res);
  51.    }
  52. }
  53.  
  54. double factorial(x)
  55. int x;
  56. {
  57.    double r = 1.0;
  58.  
  59.    if (x > 250) r = HUGE; /* Certainly too big */
  60.    else for (; x > 0; x--) r *= x;
  61.  
  62.    return(r);
  63. }
  64.  
  65. double Perm(x, y)
  66. int x, y;
  67. {
  68.    double i, res = 1.0, lim = x - y;
  69.  
  70.    for (i = x; i > lim; i -= 1.0) res *= i;
  71.  
  72.    return(res);
  73. }
  74.  
  75. double Comb(x, y)
  76. int x,y;
  77. {
  78.    double i, lim = y, res = Perm(x, y);
  79.  
  80.    for (i = 1; i <= lim; i += 1.0) res /= i;
  81.  
  82.    return(res);
  83. }
  84.  
  85. double hr(x)
  86. double x;
  87. {
  88.    double h, m, s;
  89.  
  90.    /* f = modf(x, &i) returns the frcational part of x in f and the integral part in i (all double) */
  91.    m = 100.0 * modf(x, &h);
  92.    s = 100.0 * modf(m, &m);
  93.  
  94.    return(h + m / 60.0 + s / 3600.0);
  95. }
  96.  
  97. double hms(x)
  98. double x;
  99. {
  100.    double h, m, s;
  101.  
  102.    m = 60.0 * modf(x, &h);
  103.    s = 60.0 * modf(m, &m);
  104.  
  105.    return(h + m / 100.0 + s / 10000.0);
  106. }
  107.  
  108. double trunc(x)
  109. double x;
  110. {
  111.    modf(x, &x);
  112.    return(x);
  113. }
  114.  
  115. double frac(x)
  116. double x;
  117. {
  118.    return(modf(x, &x));
  119. }
  120.  
  121. double asinh(x)
  122. double x;
  123. {
  124.    return(log(x + sqrt(x * x + 1)));
  125. }
  126.  
  127. double acosh(x)
  128. double x;
  129. {
  130.    if (x < 1.0) return(0.0);
  131.    else return(log(x + sqrt(x * x -1)));
  132. }
  133.  
  134. double atanh(x)
  135. double x;
  136. {
  137.    if (x > 1.0) return(0.0);
  138.    else return(log((1.0 + x) / (1.0 - x)) / 2.0);
  139. }
  140.