1:
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37:
38:
39: #include <sys/cdefs.h>
40: #include <float.h>
41: #include <math.h>
42:
43: #include "math_private.h"
44:
45: static const double
46: one= 1.00000000000000000000e+00,
47: pi = 3.14159265358979311600e+00,
48: pio2_hi = 1.57079632679489655800e+00,
49: pio2_lo = 6.12323399573676603587e-17,
50: pS0 = 1.66666666666666657415e-01,
51: pS1 = -3.25565818622400915405e-01,
52: pS2 = 2.01212532134862925881e-01,
53: pS3 = -4.00555345006794114027e-02,
54: pS4 = 7.91534994289814532176e-04,
55: pS5 = 3.47933107596021167570e-05,
56: qS1 = -2.40339491173441421878e+00,
57: qS2 = 2.02094576023350569471e+00,
58: qS3 = -6.88283971605453293030e-01,
59: qS4 = 7.70381505559019352791e-02;
60:
61: double
62: acos(double x)
63: {
64: double z,p,q,r,w,s,c,df;
65: int32_t hx,ix;
66: GET_HIGH_WORD(hx,x);
67: ix = hx&0x7fffffff;
68: if(ix>=0x3ff00000) {
69: u_int32_t lx;
70: GET_LOW_WORD(lx,x);
71: if(((ix-0x3ff00000)|lx)==0) {
72: if(hx>0) return 0.0;
73: else return pi+2.0*pio2_lo;
74: }
75: return (x-x)/(x-x);
76: }
77: if(ix<0x3fe00000) {
78: if(ix<=0x3c600000) return pio2_hi+pio2_lo;
79: z = x*x;
80: p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
81: q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
82: r = p/q;
83: return pio2_hi - (x - (pio2_lo-x*r));
84: } else if (hx<0) {
85: z = (one+x)*0.5;
86: p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
87: q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
88: s = sqrt(z);
89: r = p/q;
90: w = r*s-pio2_lo;
91: return pi - 2.0*(s+w);
92: } else {
93: z = (one-x)*0.5;
94: s = sqrt(z);
95: df = s;
96: SET_LOW_WORD(df,0);
97: c = (z-df*df)/(s+df);
98: p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
99: q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
100: r = p/q;
101: w = r*s+c;
102: return 2.0*(df+w);
103: }
104: }
105:
106: #if LDBL_MANT_DIG == 53
107: #ifdef lint
108:
109: long double acosl(long double);
110: #else
111: __weak_alias(acosl, acos);
112: #endif
113: #endif