1: 2: 3:
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: #include "math.h"
17: #include "math_private.h"
18:
19: static const float
20: tiny = 1.0e-30,
21: zero = 0.0,
22: pi_o_4 = 7.8539818525e-01,
23: pi_o_2 = 1.5707963705e+00,
24: pi = 3.1415925026e+00,
25: pi_lo = 1.5099578832e-07;
26:
27: float
28: atan2f(float y, float x)
29: {
30: float z;
31: int32_t k,m,hx,hy,ix,iy;
32:
33: GET_FLOAT_WORD(hx,x);
34: ix = hx&0x7fffffff;
35: GET_FLOAT_WORD(hy,y);
36: iy = hy&0x7fffffff;
37: if((ix>0x7f800000)||
38: (iy>0x7f800000))
39: return x+y;
40: if(hx==0x3f800000) return atanf(y);
41: m = ((hy>>31)&1)|((hx>>30)&2);
42:
43:
44: if(iy==0) {
45: switch(m) {
46: case 0:
47: case 1: return y;
48: case 2: return pi+tiny;
49: case 3: return -pi-tiny;
50: }
51: }
52:
53: if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
54:
55:
56: if(ix==0x7f800000) {
57: if(iy==0x7f800000) {
58: switch(m) {
59: case 0: return pi_o_4+tiny;
60: case 1: return -pi_o_4-tiny;
61: case 2: return (float)3.0*pi_o_4+tiny;
62: case 3: return (float)-3.0*pi_o_4-tiny;
63: }
64: } else {
65: switch(m) {
66: case 0: return zero ;
67: case 1: return -zero ;
68: case 2: return pi+tiny ;
69: case 3: return -pi-tiny ;
70: }
71: }
72: }
73:
74: if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
75:
76:
77: k = (iy-ix)>>23;
78: if(k > 60) z=pi_o_2+(float)0.5*pi_lo;
79: else if(hx<0&&k<-60) z=0.0;
80: else z=atanf(fabsf(y/x));
81: switch (m) {
82: case 0: return z ;
83: case 1: {
84: u_int32_t zh;
85: GET_FLOAT_WORD(zh,z);
86: SET_FLOAT_WORD(z,zh ^ 0x80000000);
87: }
88: return z ;
89: case 2: return pi-(z-pi_lo);
90: default:
91: return (z-pi_lo)-pi;
92: }
93: }