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

  1. # double atan(arg1); -pi/2 < atan < pi/2
  2. #double atan2(arg1,arg2); -pi< atan2<pi
  3. #double arg1,arg2
  4. #method: range reduction to [sqrt(2)-1,sqrt(2)+1]
  5. # followed by Hart&Cheney ARCTN 5076 D=17.55
  6. # J. F. Jarvis August 8, 1978
  7. .globl    _atan
  8. .globl    _atan2
  9. .text
  10. .align    1
  11. _atan:
  12.     .word    0x03c0
  13.     movd    4(ap),r0
  14.     jgtr    a1
  15.     mnegd    r0,r0    # atan(arg1), arg1<0
  16.     bsbb    satan
  17.     mnegd    r0,r0
  18.     ret
  19. a1:    bsbb    satan    # atan(arg1), arg1>=0
  20.     ret
  21. #
  22. .align    1
  23. _atan2:
  24.     .word    0x03c0
  25.     movd    4(ap),r0    # atan(arg1/arg2)
  26.     movd    12(ap),r2
  27.     addd3    r0,r2,r4
  28.     cmpd    r0,r4
  29.     jneq    b1
  30.     tstd    r0
  31.     jgeq    b2
  32.     mnegd   pio2d,r0
  33.     ret
  34. b2:     movd    pio2d,r0
  35.     ret
  36. #
  37. b1:    tstd    r2
  38.     jgeq    b3
  39.     divd2    r2,r0
  40.     jleq    b4
  41.     bsbb    satan    # arg1<0, arg2<0
  42.     subd2    pi,r0
  43.     ret
  44. b4:    mnegd    r0,r0    # arg1>0, arg2<0
  45.     bsbb    satan
  46.     subd3    r0,pi,r0
  47.     ret
  48. #
  49. b3:    divd2    r2,r0
  50.     jleq    b5
  51.     bsbb    satan    # arg1>0, arg2>0
  52.     ret
  53. b5:    mnegd    r0,r0    # arg1<0, arg2>0
  54.     bsbb    satan
  55.     mnegd    r0,r0
  56.     ret
  57. #
  58. .globl    satan
  59. satan:    # range reduction on positive arg(r0)
  60.     cvtdf   r0,r0
  61.  
  62.     cmpf    r0,sq2m1
  63.     jgeq    c1
  64.     bsbb    xatan
  65.     rsb
  66. c1:     cmpf    r0,sq2p1
  67.     jleq    c2
  68.     divf3   r0,$0d1.0e+0,r0
  69.     bsbb    xatan
  70.     subf3   r0,pio2f,r0
  71.     rsb
  72. c2:     addf3   $0d1.0e+0,r0,r2
  73.     subf2   $0d1.0e+0,r0
  74.     divf2   r2,r0
  75.     bsbb    xatan
  76.     addf2   pio4f,r0
  77.  
  78.     cvtfd   r0,r0
  79.     rsb
  80. #
  81. xatan:    # compute arctan(r0) for:sqrt(2)-1<r0<sqrt(2)+1
  82. # Hart&Cheney ARCTN 5076 is evaluated
  83.     cvtdf   r0,r0
  84.  
  85.     movf    r0,r8
  86.     mulf3   r0,r0,r6
  87.     polyf   r6,$4,pcoef
  88.     mulf2   r0,r8
  89.     polyf   r6,$4,qcoef
  90.     divf3   r0,r8,r0
  91.  
  92.     cvtdf   r0,r0
  93.     rsb
  94. .data
  95. .align    2
  96. pcoef:
  97.     .float 0d0.1589740288482307048e+0
  98.     .float 0d0.66605790170092626575e+1
  99.     .float 0d0.40969264832102256374e+2
  100.     .float 0d0.77477687719204208616e+2
  101.     .float 0d0.44541340059290680319e+2
  102. qcoef:
  103.     .float 0d1.0e+0
  104.     .float 0d0.15503977551421987525e+2
  105.     .float 0d0.62835930511032376833e+2
  106.     .float 0d0.92324801072300974840e+2
  107.     .float 0d0.44541340059290680444e+2
  108.  
  109. pio4f: .float   0d0.78539816339744830961e+0
  110. pio2d: .double  0d1.57079632679489661923e+0
  111. pio2f: .float   0d1.57079632679489661923e+0
  112.  
  113. sq2p1: .float   0d2.41421356237309504880e+0
  114. sq2m1: .float  0d0.41421356237309504880e+0
  115.  
  116. pi: .double 0d3.14159265358979323846e+0
  117.