/src/moddable/xs/tools/fdlibm/e_rem_pio2.c
Line | Count | Source |
1 | | |
2 | | /* |
3 | | * ==================================================== |
4 | | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
5 | | * |
6 | | * Developed at SunSoft, a Sun Microsystems, Inc. business. |
7 | | * Permission to use, copy, modify, and distribute this |
8 | | * software is freely granted, provided that this notice |
9 | | * is preserved. |
10 | | * ==================================================== |
11 | | * |
12 | | * Optimized by Bruce D. Evans. |
13 | | */ |
14 | | |
15 | | /* __ieee754_rem_pio2(x,y) |
16 | | * |
17 | | * return the remainder of x rem pi/2 in y[0]+y[1] |
18 | | * use __kernel_rem_pio2() |
19 | | */ |
20 | | |
21 | | #include "math_private.h" |
22 | | |
23 | | /* |
24 | | * invpio2: 53 bits of 2/pi |
25 | | * pio2_1: first 33 bit of pi/2 |
26 | | * pio2_1t: pi/2 - pio2_1 |
27 | | * pio2_2: second 33 bit of pi/2 |
28 | | * pio2_2t: pi/2 - (pio2_1+pio2_2) |
29 | | * pio2_3: third 33 bit of pi/2 |
30 | | * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) |
31 | | */ |
32 | | |
33 | | static const double |
34 | | zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ |
35 | | two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ |
36 | | invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ |
37 | | pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ |
38 | | pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ |
39 | | pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ |
40 | | pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ |
41 | | pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ |
42 | | pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ |
43 | | |
44 | | #ifdef INLINE_REM_PIO2 |
45 | | static inline |
46 | | #endif |
47 | | int |
48 | | __ieee754_rem_pio2(double x, double *y) |
49 | 160k | { |
50 | 160k | double z,w,t,r,fn; |
51 | 160k | double tx[3],ty[2]; |
52 | 160k | int32_t e0,i,j,nx,n,ix,hx; |
53 | 160k | u_int32_t low; |
54 | | |
55 | 160k | GET_HIGH_WORD(hx,x); /* high word of x */ |
56 | 160k | ix = hx&0x7fffffff; |
57 | | #if 0 /* Must be handled in caller. */ |
58 | | if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ |
59 | | {y[0] = x; y[1] = 0; return 0;} |
60 | | #endif |
61 | 160k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ |
62 | 110k | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ |
63 | 0 | goto medium; /* cancellation -- use medium case */ |
64 | 110k | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ |
65 | 105k | if (hx > 0) { |
66 | 102k | z = x - pio2_1; /* one round good to 85 bits */ |
67 | 102k | y[0] = z - pio2_1t; |
68 | 102k | y[1] = (z-y[0])-pio2_1t; |
69 | 102k | return 1; |
70 | 102k | } else { |
71 | 3.40k | z = x + pio2_1; |
72 | 3.40k | y[0] = z + pio2_1t; |
73 | 3.40k | y[1] = (z-y[0])+pio2_1t; |
74 | 3.40k | return -1; |
75 | 3.40k | } |
76 | 105k | } else { |
77 | 4.84k | if (hx > 0) { |
78 | 1.01k | z = x - 2*pio2_1; |
79 | 1.01k | y[0] = z - 2*pio2_1t; |
80 | 1.01k | y[1] = (z-y[0])-2*pio2_1t; |
81 | 1.01k | return 2; |
82 | 3.82k | } else { |
83 | 3.82k | z = x + 2*pio2_1; |
84 | 3.82k | y[0] = z + 2*pio2_1t; |
85 | 3.82k | y[1] = (z-y[0])+2*pio2_1t; |
86 | 3.82k | return -2; |
87 | 3.82k | } |
88 | 4.84k | } |
89 | 110k | } |
90 | 49.8k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ |
91 | 7.22k | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ |
92 | 3.70k | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ |
93 | 0 | goto medium; |
94 | 3.70k | if (hx > 0) { |
95 | 877 | z = x - 3*pio2_1; |
96 | 877 | y[0] = z - 3*pio2_1t; |
97 | 877 | y[1] = (z-y[0])-3*pio2_1t; |
98 | 877 | return 3; |
99 | 2.82k | } else { |
100 | 2.82k | z = x + 3*pio2_1; |
101 | 2.82k | y[0] = z + 3*pio2_1t; |
102 | 2.82k | y[1] = (z-y[0])+3*pio2_1t; |
103 | 2.82k | return -3; |
104 | 2.82k | } |
105 | 3.70k | } else { |
106 | 3.52k | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ |
107 | 0 | goto medium; |
108 | 3.52k | if (hx > 0) { |
109 | 825 | z = x - 4*pio2_1; |
110 | 825 | y[0] = z - 4*pio2_1t; |
111 | 825 | y[1] = (z-y[0])-4*pio2_1t; |
112 | 825 | return 4; |
113 | 2.70k | } else { |
114 | 2.70k | z = x + 4*pio2_1; |
115 | 2.70k | y[0] = z + 4*pio2_1t; |
116 | 2.70k | y[1] = (z-y[0])+4*pio2_1t; |
117 | 2.70k | return -4; |
118 | 2.70k | } |
119 | 3.52k | } |
120 | 7.22k | } |
121 | 42.6k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ |
122 | 34.5k | medium: |
123 | 34.5k | fn = rnint((double_t)x*invpio2); |
124 | 34.5k | n = irint(fn); |
125 | 34.5k | r = x-fn*pio2_1; |
126 | 34.5k | w = fn*pio2_1t; /* 1st round good to 85 bit */ |
127 | 34.5k | { |
128 | 34.5k | u_int32_t high; |
129 | 34.5k | j = ix>>20; |
130 | 34.5k | y[0] = r-w; |
131 | 34.5k | GET_HIGH_WORD(high,y[0]); |
132 | 34.5k | i = j-((high>>20)&0x7ff); |
133 | 34.5k | if(i>16) { /* 2nd iteration needed, good to 118 */ |
134 | 699 | t = r; |
135 | 699 | w = fn*pio2_2; |
136 | 699 | r = t-w; |
137 | 699 | w = fn*pio2_2t-((t-r)-w); |
138 | 699 | y[0] = r-w; |
139 | 699 | GET_HIGH_WORD(high,y[0]); |
140 | 699 | i = j-((high>>20)&0x7ff); |
141 | 699 | if(i>49) { /* 3rd iteration need, 151 bits acc */ |
142 | 0 | t = r; /* will cover all possible cases */ |
143 | 0 | w = fn*pio2_3; |
144 | 0 | r = t-w; |
145 | 0 | w = fn*pio2_3t-((t-r)-w); |
146 | 0 | y[0] = r-w; |
147 | 0 | } |
148 | 699 | } |
149 | 34.5k | } |
150 | 34.5k | y[1] = (r-y[0])-w; |
151 | 34.5k | return n; |
152 | 34.5k | } |
153 | | /* |
154 | | * all other (large) arguments |
155 | | */ |
156 | 8.09k | if(ix>=0x7ff00000) { /* x is inf or NaN */ |
157 | 0 | y[0]=y[1]=x-x; return 0; |
158 | 0 | } |
159 | | /* set z = scalbn(|x|,ilogb(x)-23) */ |
160 | 8.09k | GET_LOW_WORD(low,x); |
161 | 8.09k | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ |
162 | 8.09k | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); |
163 | 24.2k | for(i=0;i<2;i++) { |
164 | 16.1k | tx[i] = (double)((int32_t)(z)); |
165 | 16.1k | z = (z-tx[i])*two24; |
166 | 16.1k | } |
167 | 8.09k | tx[2] = z; |
168 | 8.09k | nx = 3; |
169 | 17.0k | while(tx[nx-1]==zero) nx--; /* skip zero term */ |
170 | 8.09k | n = __kernel_rem_pio2(tx,ty,e0,nx,1); |
171 | 8.09k | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} |
172 | 4.37k | y[0] = ty[0]; y[1] = ty[1]; return n; |
173 | 8.09k | } Unexecuted instantiation: __ieee754_rem_pio2 s_cos.c:__ieee754_rem_pio2 Line | Count | Source | 49 | 144k | { | 50 | 144k | double z,w,t,r,fn; | 51 | 144k | double tx[3],ty[2]; | 52 | 144k | int32_t e0,i,j,nx,n,ix,hx; | 53 | 144k | u_int32_t low; | 54 | | | 55 | 144k | GET_HIGH_WORD(hx,x); /* high word of x */ | 56 | 144k | ix = hx&0x7fffffff; | 57 | | #if 0 /* Must be handled in caller. */ | 58 | | if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ | 59 | | {y[0] = x; y[1] = 0; return 0;} | 60 | | #endif | 61 | 144k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ | 62 | 106k | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ | 63 | 0 | goto medium; /* cancellation -- use medium case */ | 64 | 106k | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ | 65 | 103k | if (hx > 0) { | 66 | 100k | z = x - pio2_1; /* one round good to 85 bits */ | 67 | 100k | y[0] = z - pio2_1t; | 68 | 100k | y[1] = (z-y[0])-pio2_1t; | 69 | 100k | return 1; | 70 | 100k | } else { | 71 | 2.76k | z = x + pio2_1; | 72 | 2.76k | y[0] = z + pio2_1t; | 73 | 2.76k | y[1] = (z-y[0])+pio2_1t; | 74 | 2.76k | return -1; | 75 | 2.76k | } | 76 | 103k | } else { | 77 | 3.16k | if (hx > 0) { | 78 | 619 | z = x - 2*pio2_1; | 79 | 619 | y[0] = z - 2*pio2_1t; | 80 | 619 | y[1] = (z-y[0])-2*pio2_1t; | 81 | 619 | return 2; | 82 | 2.54k | } else { | 83 | 2.54k | z = x + 2*pio2_1; | 84 | 2.54k | y[0] = z + 2*pio2_1t; | 85 | 2.54k | y[1] = (z-y[0])+2*pio2_1t; | 86 | 2.54k | return -2; | 87 | 2.54k | } | 88 | 3.16k | } | 89 | 106k | } | 90 | 37.5k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ | 91 | 4.84k | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ | 92 | 2.03k | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ | 93 | 0 | goto medium; | 94 | 2.03k | if (hx > 0) { | 95 | 548 | z = x - 3*pio2_1; | 96 | 548 | y[0] = z - 3*pio2_1t; | 97 | 548 | y[1] = (z-y[0])-3*pio2_1t; | 98 | 548 | return 3; | 99 | 1.48k | } else { | 100 | 1.48k | z = x + 3*pio2_1; | 101 | 1.48k | y[0] = z + 3*pio2_1t; | 102 | 1.48k | y[1] = (z-y[0])+3*pio2_1t; | 103 | 1.48k | return -3; | 104 | 1.48k | } | 105 | 2.81k | } else { | 106 | 2.81k | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ | 107 | 0 | goto medium; | 108 | 2.81k | if (hx > 0) { | 109 | 379 | z = x - 4*pio2_1; | 110 | 379 | y[0] = z - 4*pio2_1t; | 111 | 379 | y[1] = (z-y[0])-4*pio2_1t; | 112 | 379 | return 4; | 113 | 2.43k | } else { | 114 | 2.43k | z = x + 4*pio2_1; | 115 | 2.43k | y[0] = z + 4*pio2_1t; | 116 | 2.43k | y[1] = (z-y[0])+4*pio2_1t; | 117 | 2.43k | return -4; | 118 | 2.43k | } | 119 | 2.81k | } | 120 | 4.84k | } | 121 | 32.6k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ | 122 | 32.2k | medium: | 123 | 32.2k | fn = rnint((double_t)x*invpio2); | 124 | 32.2k | n = irint(fn); | 125 | 32.2k | r = x-fn*pio2_1; | 126 | 32.2k | w = fn*pio2_1t; /* 1st round good to 85 bit */ | 127 | 32.2k | { | 128 | 32.2k | u_int32_t high; | 129 | 32.2k | j = ix>>20; | 130 | 32.2k | y[0] = r-w; | 131 | 32.2k | GET_HIGH_WORD(high,y[0]); | 132 | 32.2k | i = j-((high>>20)&0x7ff); | 133 | 32.2k | if(i>16) { /* 2nd iteration needed, good to 118 */ | 134 | 157 | t = r; | 135 | 157 | w = fn*pio2_2; | 136 | 157 | r = t-w; | 137 | 157 | w = fn*pio2_2t-((t-r)-w); | 138 | 157 | y[0] = r-w; | 139 | 157 | GET_HIGH_WORD(high,y[0]); | 140 | 157 | i = j-((high>>20)&0x7ff); | 141 | 157 | if(i>49) { /* 3rd iteration need, 151 bits acc */ | 142 | 0 | t = r; /* will cover all possible cases */ | 143 | 0 | w = fn*pio2_3; | 144 | 0 | r = t-w; | 145 | 0 | w = fn*pio2_3t-((t-r)-w); | 146 | 0 | y[0] = r-w; | 147 | 0 | } | 148 | 157 | } | 149 | 32.2k | } | 150 | 32.2k | y[1] = (r-y[0])-w; | 151 | 32.2k | return n; | 152 | 32.2k | } | 153 | | /* | 154 | | * all other (large) arguments | 155 | | */ | 156 | 481 | if(ix>=0x7ff00000) { /* x is inf or NaN */ | 157 | 0 | y[0]=y[1]=x-x; return 0; | 158 | 0 | } | 159 | | /* set z = scalbn(|x|,ilogb(x)-23) */ | 160 | 481 | GET_LOW_WORD(low,x); | 161 | 481 | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ | 162 | 481 | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); | 163 | 1.44k | for(i=0;i<2;i++) { | 164 | 962 | tx[i] = (double)((int32_t)(z)); | 165 | 962 | z = (z-tx[i])*two24; | 166 | 962 | } | 167 | 481 | tx[2] = z; | 168 | 481 | nx = 3; | 169 | 898 | while(tx[nx-1]==zero) nx--; /* skip zero term */ | 170 | 481 | n = __kernel_rem_pio2(tx,ty,e0,nx,1); | 171 | 481 | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} | 172 | 137 | y[0] = ty[0]; y[1] = ty[1]; return n; | 173 | 481 | } |
s_sin.c:__ieee754_rem_pio2 Line | Count | Source | 49 | 8.31k | { | 50 | 8.31k | double z,w,t,r,fn; | 51 | 8.31k | double tx[3],ty[2]; | 52 | 8.31k | int32_t e0,i,j,nx,n,ix,hx; | 53 | 8.31k | u_int32_t low; | 54 | | | 55 | 8.31k | GET_HIGH_WORD(hx,x); /* high word of x */ | 56 | 8.31k | ix = hx&0x7fffffff; | 57 | | #if 0 /* Must be handled in caller. */ | 58 | | if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ | 59 | | {y[0] = x; y[1] = 0; return 0;} | 60 | | #endif | 61 | 8.31k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ | 62 | 2.68k | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ | 63 | 0 | goto medium; /* cancellation -- use medium case */ | 64 | 2.68k | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ | 65 | 1.21k | if (hx > 0) { | 66 | 823 | z = x - pio2_1; /* one round good to 85 bits */ | 67 | 823 | y[0] = z - pio2_1t; | 68 | 823 | y[1] = (z-y[0])-pio2_1t; | 69 | 823 | return 1; | 70 | 823 | } else { | 71 | 391 | z = x + pio2_1; | 72 | 391 | y[0] = z + pio2_1t; | 73 | 391 | y[1] = (z-y[0])+pio2_1t; | 74 | 391 | return -1; | 75 | 391 | } | 76 | 1.46k | } else { | 77 | 1.46k | if (hx > 0) { | 78 | 302 | z = x - 2*pio2_1; | 79 | 302 | y[0] = z - 2*pio2_1t; | 80 | 302 | y[1] = (z-y[0])-2*pio2_1t; | 81 | 302 | return 2; | 82 | 1.16k | } else { | 83 | 1.16k | z = x + 2*pio2_1; | 84 | 1.16k | y[0] = z + 2*pio2_1t; | 85 | 1.16k | y[1] = (z-y[0])+2*pio2_1t; | 86 | 1.16k | return -2; | 87 | 1.16k | } | 88 | 1.46k | } | 89 | 2.68k | } | 90 | 5.63k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ | 91 | 1.59k | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ | 92 | 1.17k | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ | 93 | 0 | goto medium; | 94 | 1.17k | if (hx > 0) { | 95 | 134 | z = x - 3*pio2_1; | 96 | 134 | y[0] = z - 3*pio2_1t; | 97 | 134 | y[1] = (z-y[0])-3*pio2_1t; | 98 | 134 | return 3; | 99 | 1.04k | } else { | 100 | 1.04k | z = x + 3*pio2_1; | 101 | 1.04k | y[0] = z + 3*pio2_1t; | 102 | 1.04k | y[1] = (z-y[0])+3*pio2_1t; | 103 | 1.04k | return -3; | 104 | 1.04k | } | 105 | 1.17k | } else { | 106 | 416 | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ | 107 | 0 | goto medium; | 108 | 416 | if (hx > 0) { | 109 | 251 | z = x - 4*pio2_1; | 110 | 251 | y[0] = z - 4*pio2_1t; | 111 | 251 | y[1] = (z-y[0])-4*pio2_1t; | 112 | 251 | return 4; | 113 | 251 | } else { | 114 | 165 | z = x + 4*pio2_1; | 115 | 165 | y[0] = z + 4*pio2_1t; | 116 | 165 | y[1] = (z-y[0])+4*pio2_1t; | 117 | 165 | return -4; | 118 | 165 | } | 119 | 416 | } | 120 | 1.59k | } | 121 | 4.04k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ | 122 | 1.35k | medium: | 123 | 1.35k | fn = rnint((double_t)x*invpio2); | 124 | 1.35k | n = irint(fn); | 125 | 1.35k | r = x-fn*pio2_1; | 126 | 1.35k | w = fn*pio2_1t; /* 1st round good to 85 bit */ | 127 | 1.35k | { | 128 | 1.35k | u_int32_t high; | 129 | 1.35k | j = ix>>20; | 130 | 1.35k | y[0] = r-w; | 131 | 1.35k | GET_HIGH_WORD(high,y[0]); | 132 | 1.35k | i = j-((high>>20)&0x7ff); | 133 | 1.35k | if(i>16) { /* 2nd iteration needed, good to 118 */ | 134 | 178 | t = r; | 135 | 178 | w = fn*pio2_2; | 136 | 178 | r = t-w; | 137 | 178 | w = fn*pio2_2t-((t-r)-w); | 138 | 178 | y[0] = r-w; | 139 | 178 | GET_HIGH_WORD(high,y[0]); | 140 | 178 | i = j-((high>>20)&0x7ff); | 141 | 178 | if(i>49) { /* 3rd iteration need, 151 bits acc */ | 142 | 0 | t = r; /* will cover all possible cases */ | 143 | 0 | w = fn*pio2_3; | 144 | 0 | r = t-w; | 145 | 0 | w = fn*pio2_3t-((t-r)-w); | 146 | 0 | y[0] = r-w; | 147 | 0 | } | 148 | 178 | } | 149 | 1.35k | } | 150 | 1.35k | y[1] = (r-y[0])-w; | 151 | 1.35k | return n; | 152 | 1.35k | } | 153 | | /* | 154 | | * all other (large) arguments | 155 | | */ | 156 | 2.68k | if(ix>=0x7ff00000) { /* x is inf or NaN */ | 157 | 0 | y[0]=y[1]=x-x; return 0; | 158 | 0 | } | 159 | | /* set z = scalbn(|x|,ilogb(x)-23) */ | 160 | 2.68k | GET_LOW_WORD(low,x); | 161 | 2.68k | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ | 162 | 2.68k | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); | 163 | 8.06k | for(i=0;i<2;i++) { | 164 | 5.37k | tx[i] = (double)((int32_t)(z)); | 165 | 5.37k | z = (z-tx[i])*two24; | 166 | 5.37k | } | 167 | 2.68k | tx[2] = z; | 168 | 2.68k | nx = 3; | 169 | 7.47k | while(tx[nx-1]==zero) nx--; /* skip zero term */ | 170 | 2.68k | n = __kernel_rem_pio2(tx,ty,e0,nx,1); | 171 | 2.68k | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} | 172 | 1.08k | y[0] = ty[0]; y[1] = ty[1]; return n; | 173 | 2.68k | } |
s_tan.c:__ieee754_rem_pio2 Line | Count | Source | 49 | 7.67k | { | 50 | 7.67k | double z,w,t,r,fn; | 51 | 7.67k | double tx[3],ty[2]; | 52 | 7.67k | int32_t e0,i,j,nx,n,ix,hx; | 53 | 7.67k | u_int32_t low; | 54 | | | 55 | 7.67k | GET_HIGH_WORD(hx,x); /* high word of x */ | 56 | 7.67k | ix = hx&0x7fffffff; | 57 | | #if 0 /* Must be handled in caller. */ | 58 | | if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ | 59 | | {y[0] = x; y[1] = 0; return 0;} | 60 | | #endif | 61 | 7.67k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ | 62 | 992 | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ | 63 | 0 | goto medium; /* cancellation -- use medium case */ | 64 | 992 | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ | 65 | 785 | if (hx > 0) { | 66 | 536 | z = x - pio2_1; /* one round good to 85 bits */ | 67 | 536 | y[0] = z - pio2_1t; | 68 | 536 | y[1] = (z-y[0])-pio2_1t; | 69 | 536 | return 1; | 70 | 536 | } else { | 71 | 249 | z = x + pio2_1; | 72 | 249 | y[0] = z + pio2_1t; | 73 | 249 | y[1] = (z-y[0])+pio2_1t; | 74 | 249 | return -1; | 75 | 249 | } | 76 | 785 | } else { | 77 | 207 | if (hx > 0) { | 78 | 96 | z = x - 2*pio2_1; | 79 | 96 | y[0] = z - 2*pio2_1t; | 80 | 96 | y[1] = (z-y[0])-2*pio2_1t; | 81 | 96 | return 2; | 82 | 111 | } else { | 83 | 111 | z = x + 2*pio2_1; | 84 | 111 | y[0] = z + 2*pio2_1t; | 85 | 111 | y[1] = (z-y[0])+2*pio2_1t; | 86 | 111 | return -2; | 87 | 111 | } | 88 | 207 | } | 89 | 992 | } | 90 | 6.67k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ | 91 | 789 | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ | 92 | 491 | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ | 93 | 0 | goto medium; | 94 | 491 | if (hx > 0) { | 95 | 195 | z = x - 3*pio2_1; | 96 | 195 | y[0] = z - 3*pio2_1t; | 97 | 195 | y[1] = (z-y[0])-3*pio2_1t; | 98 | 195 | return 3; | 99 | 296 | } else { | 100 | 296 | z = x + 3*pio2_1; | 101 | 296 | y[0] = z + 3*pio2_1t; | 102 | 296 | y[1] = (z-y[0])+3*pio2_1t; | 103 | 296 | return -3; | 104 | 296 | } | 105 | 491 | } else { | 106 | 298 | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ | 107 | 0 | goto medium; | 108 | 298 | if (hx > 0) { | 109 | 195 | z = x - 4*pio2_1; | 110 | 195 | y[0] = z - 4*pio2_1t; | 111 | 195 | y[1] = (z-y[0])-4*pio2_1t; | 112 | 195 | return 4; | 113 | 195 | } else { | 114 | 103 | z = x + 4*pio2_1; | 115 | 103 | y[0] = z + 4*pio2_1t; | 116 | 103 | y[1] = (z-y[0])+4*pio2_1t; | 117 | 103 | return -4; | 118 | 103 | } | 119 | 298 | } | 120 | 789 | } | 121 | 5.89k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ | 122 | 969 | medium: | 123 | 969 | fn = rnint((double_t)x*invpio2); | 124 | 969 | n = irint(fn); | 125 | 969 | r = x-fn*pio2_1; | 126 | 969 | w = fn*pio2_1t; /* 1st round good to 85 bit */ | 127 | 969 | { | 128 | 969 | u_int32_t high; | 129 | 969 | j = ix>>20; | 130 | 969 | y[0] = r-w; | 131 | 969 | GET_HIGH_WORD(high,y[0]); | 132 | 969 | i = j-((high>>20)&0x7ff); | 133 | 969 | if(i>16) { /* 2nd iteration needed, good to 118 */ | 134 | 364 | t = r; | 135 | 364 | w = fn*pio2_2; | 136 | 364 | r = t-w; | 137 | 364 | w = fn*pio2_2t-((t-r)-w); | 138 | 364 | y[0] = r-w; | 139 | 364 | GET_HIGH_WORD(high,y[0]); | 140 | 364 | i = j-((high>>20)&0x7ff); | 141 | 364 | if(i>49) { /* 3rd iteration need, 151 bits acc */ | 142 | 0 | t = r; /* will cover all possible cases */ | 143 | 0 | w = fn*pio2_3; | 144 | 0 | r = t-w; | 145 | 0 | w = fn*pio2_3t-((t-r)-w); | 146 | 0 | y[0] = r-w; | 147 | 0 | } | 148 | 364 | } | 149 | 969 | } | 150 | 969 | y[1] = (r-y[0])-w; | 151 | 969 | return n; | 152 | 969 | } | 153 | | /* | 154 | | * all other (large) arguments | 155 | | */ | 156 | 4.92k | if(ix>=0x7ff00000) { /* x is inf or NaN */ | 157 | 0 | y[0]=y[1]=x-x; return 0; | 158 | 0 | } | 159 | | /* set z = scalbn(|x|,ilogb(x)-23) */ | 160 | 4.92k | GET_LOW_WORD(low,x); | 161 | 4.92k | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ | 162 | 4.92k | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); | 163 | 14.7k | for(i=0;i<2;i++) { | 164 | 9.84k | tx[i] = (double)((int32_t)(z)); | 165 | 9.84k | z = (z-tx[i])*two24; | 166 | 9.84k | } | 167 | 4.92k | tx[2] = z; | 168 | 4.92k | nx = 3; | 169 | 8.67k | while(tx[nx-1]==zero) nx--; /* skip zero term */ | 170 | 4.92k | n = __kernel_rem_pio2(tx,ty,e0,nx,1); | 171 | 4.92k | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} | 172 | 3.15k | y[0] = ty[0]; y[1] = ty[1]; return n; | 173 | 4.92k | } |
|