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

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