home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / 500 / 471 / rccl123 < prev    next >
Text File  |  1987-03-02  |  2KB  |  117 lines

  1. #include "arch.h"
  2.  
  3. double sin(a)
  4. double a;
  5. {
  6.     register int i, q;
  7.     float h;
  8.     float fa = a, ftbpi = TBPI, fst = ST;
  9.  
  10.     h = fa * ftbpi;
  11.     i = h * fst;
  12.     q = h;
  13.     if (i < 0) {
  14.         i = -i;
  15.         q = 2 - q;
  16.     }
  17.     switch (q & 03) {
  18.     case 0 :
  19.         return(st[i & MMAS]);
  20.     case 1 :
  21.         return(st[ST - 1 - (i & MMAS)]);
  22.     case 2 :
  23.         return(-st[i & MMAS]);
  24.     case 3:
  25.         return(-st[ST - 1 - (i & MMAS)]);
  26.     }
  27. }
  28.  
  29.  
  30. double cos(a)
  31. double a;
  32. {
  33.     register int i, q;
  34.     float h;
  35.     float fa = a, ftbpi = TBPI, fst = ST;
  36.  
  37.     h = fa * ftbpi;
  38.     i = h * fst; i += ST;
  39.     q = h + 1;
  40.     if (i < 0) {
  41.         i = -i;
  42.         q = -q + 2;
  43.     }
  44.     switch (q & 03) {
  45.     case 0 :
  46.         return(st[i & MMAS]);
  47.     case 1 :
  48.         return(st[ST - 1 - (i & MMAS)]);
  49.     case 2 :
  50.         return(-st[i & MMAS]);
  51.     case 3:
  52.         return(-st[ST - 1 - (i & MMAS)]);
  53.     }
  54. }
  55.  
  56.  
  57. #define ABS(n)  ((n < 0.) ? -n : n)
  58.  
  59. double atan2(y, x)
  60. double y, x;
  61. {
  62.     register int i;
  63.     float fy = y, fx = x;
  64.     float fat = AT, h;
  65.  
  66.     if (fy + fx == fy) {
  67.         if (fy >= 0.) {
  68.             return(PIB2);
  69.         }
  70.         else {
  71.             return(-PIB2);
  72.         }
  73.     }
  74.     if (ABS(fy) <= ABS(fx)) {
  75.         h = fy / fx;
  76.         h *= fat;
  77.         i = h;
  78.         if (fx > 0.) {
  79.             if (fy > 0.) {
  80.                 return(at[i]);
  81.             }
  82.             else {
  83.                 return(-at[-i]);
  84.             }
  85.         }
  86.         else {
  87.             if (fy > 0.) {
  88.                 return(PI - at[-i]);
  89.             }
  90.             else {
  91.                 return(-PI + at[i]);
  92.             }
  93.         }
  94.     }
  95.     else {
  96.         h = fx / fy;
  97.         h *= fat;
  98.         i = h;
  99.         if (fx > 0.) {
  100.             if (fy > 0.) {
  101.                 return(PIB2 - at[i]);
  102.             }
  103.             else {
  104.                 return(-PIB2 + at[-i]);
  105.             }
  106.         }
  107.         else {
  108.             if (fy > 0.) {
  109.                 return(PIB2 + at[-i]);
  110.             }
  111.             else {
  112.                 return(-PIB2 - at[i]);
  113.             }
  114.         }
  115.     }
  116. }
  117.