Bell 32V development
[unix-history] / usr / src / libnm / atan.s
CommitLineData
7049871b
TL
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
19a1: 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 pio2,r0
33 ret
34b2: movd pio2,r0
35 ret
36#
37b1: 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
44b4: mnegd r0,r0 # arg1>0, arg2<0
45 bsbb satan
46 subd3 r0,pi,r0
47 ret
48#
49b3: divd2 r2,r0
50 jleq b5
51 bsbb satan # arg1>0, arg2>0
52 ret
53b5: mnegd r0,r0 # arg1<0, arg2>0
54 bsbb satan
55 mnegd r0,r0
56 ret
57#
58.globl satan
59satan: # range reduction on positive arg(r0)
60 cmpd r0,sq2m1
61 jgeq c1
62 bsbb xatan
63 rsb
64c1: cmpd r0,sq2p1
65 jleq c2
66 divd3 r0,$0d1.0e+0,r0
67 bsbb xatan
68 subd3 r0,pio2,r0
69 rsb
70c2: addd3 $0d1.0e+0,r0,r2
71 subd2 $0d1.0e+0,r0
72 divd2 r2,r0
73 bsbb xatan
74 addd2 pio4,r0
75 rsb
76#
77xatan: # compute arctan(r0) for:sqrt(2)-1<r0<sqrt(2)+1
78# Hart&Cheney ARCTN 5076 is evaluated
79 movd r0,r8
80 muld3 r0,r0,r6
81 polyd r6,$4,pcoef
82 muld2 r0,r8
83 polyd r6,$4,qcoef
84 divd3 r0,r8,r0
85 rsb
86.data
87.align 3
88pcoef:
89 .double 0d0.1589740288482307048e+0
90 .double 0d0.66605790170092626575e+1
91 .double 0d0.40969264832102256374e+2
92 .double 0d0.77477687719204208616e+2
93 .double 0d0.44541340059290680319e+2
94qcoef:
95 .double 0d1.0e+0
96 .double 0d0.15503977551421987525e+2
97 .double 0d0.62835930511032376833e+2
98 .double 0d0.92324801072300974840e+2
99 .double 0d0.44541340059290680444e+2
100pio4: .double 0d0.78539816339744830961e+0
101pio2: .double 0d1.57079632679489661923e+0
102sq2p1: .double 0d2.41421356237309504880e+0
103sq2m1: .double 0d0.41421356237309504880e+0
104pi: .double 0d3.14159265358979323846e+0