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: one = 1.0000000000e+00,
21: pi = 3.1415925026e+00,
22: pio2_hi = 1.5707962513e+00,
23: pio2_lo = 7.5497894159e-08,
24: pS0 = 1.6666667163e-01,
25: pS1 = -3.2556581497e-01,
26: pS2 = 2.0121252537e-01,
27: pS3 = -4.0055535734e-02,
28: pS4 = 7.9153501429e-04,
29: pS5 = 3.4793309169e-05,
30: qS1 = -2.4033949375e+00,
31: qS2 = 2.0209457874e+00,
32: qS3 = -6.8828397989e-01,
33: qS4 = 7.7038154006e-02;
34:
35: float
36: acosf(float x)
37: {
38: float z,p,q,r,w,s,c,df;
39: int32_t hx,ix;
40: GET_FLOAT_WORD(hx,x);
41: ix = hx&0x7fffffff;
42: if(ix==0x3f800000) {
43: if(hx>0) return 0.0;
44: else return pi+(float)2.0*pio2_lo;
45: } else if(ix>0x3f800000) {
46: return (x-x)/(x-x);
47: }
48: if(ix<0x3f000000) {
49: if(ix<=0x23000000) return pio2_hi+pio2_lo;
50: z = x*x;
51: p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
52: q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
53: r = p/q;
54: return pio2_hi - (x - (pio2_lo-x*r));
55: } else if (hx<0) {
56: z = (one+x)*(float)0.5;
57: p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
58: q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
59: s = sqrtf(z);
60: r = p/q;
61: w = r*s-pio2_lo;
62: return pi - (float)2.0*(s+w);
63: } else {
64: int32_t idf;
65: z = (one-x)*(float)0.5;
66: s = sqrtf(z);
67: df = s;
68: GET_FLOAT_WORD(idf,df);
69: SET_FLOAT_WORD(df,idf&0xfffff000);
70: c = (z-df*df)/(s+df);
71: p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
72: q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
73: r = p/q;
74: w = r*s+c;
75: return (float)2.0*(df+w);
76: }
77: }