/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 | 292k | { |
50 | 292k | double z,w,t,r,fn; |
51 | 292k | double tx[3],ty[2]; |
52 | 292k | int32_t e0,i,j,nx,n,ix,hx; |
53 | 292k | u_int32_t low; |
54 | | |
55 | 292k | GET_HIGH_WORD(hx,x); /* high word of x */ |
56 | 292k | 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 | 292k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ |
62 | 170k | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ |
63 | 0 | goto medium; /* cancellation -- use medium case */ |
64 | 170k | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ |
65 | 160k | if (hx > 0) { |
66 | 153k | z = x - pio2_1; /* one round good to 85 bits */ |
67 | 153k | y[0] = z - pio2_1t; |
68 | 153k | y[1] = (z-y[0])-pio2_1t; |
69 | 153k | return 1; |
70 | 153k | } else { |
71 | 7.36k | z = x + pio2_1; |
72 | 7.36k | y[0] = z + pio2_1t; |
73 | 7.36k | y[1] = (z-y[0])+pio2_1t; |
74 | 7.36k | return -1; |
75 | 7.36k | } |
76 | 160k | } else { |
77 | 10.2k | if (hx > 0) { |
78 | 2.68k | z = x - 2*pio2_1; |
79 | 2.68k | y[0] = z - 2*pio2_1t; |
80 | 2.68k | y[1] = (z-y[0])-2*pio2_1t; |
81 | 2.68k | return 2; |
82 | 7.60k | } else { |
83 | 7.60k | z = x + 2*pio2_1; |
84 | 7.60k | y[0] = z + 2*pio2_1t; |
85 | 7.60k | y[1] = (z-y[0])+2*pio2_1t; |
86 | 7.60k | return -2; |
87 | 7.60k | } |
88 | 10.2k | } |
89 | 170k | } |
90 | 121k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ |
91 | 16.1k | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ |
92 | 7.71k | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ |
93 | 0 | goto medium; |
94 | 7.71k | if (hx > 0) { |
95 | 1.89k | z = x - 3*pio2_1; |
96 | 1.89k | y[0] = z - 3*pio2_1t; |
97 | 1.89k | y[1] = (z-y[0])-3*pio2_1t; |
98 | 1.89k | return 3; |
99 | 5.81k | } else { |
100 | 5.81k | z = x + 3*pio2_1; |
101 | 5.81k | y[0] = z + 3*pio2_1t; |
102 | 5.81k | y[1] = (z-y[0])+3*pio2_1t; |
103 | 5.81k | return -3; |
104 | 5.81k | } |
105 | 8.45k | } else { |
106 | 8.45k | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ |
107 | 0 | goto medium; |
108 | 8.45k | if (hx > 0) { |
109 | 1.66k | z = x - 4*pio2_1; |
110 | 1.66k | y[0] = z - 4*pio2_1t; |
111 | 1.66k | y[1] = (z-y[0])-4*pio2_1t; |
112 | 1.66k | return 4; |
113 | 6.78k | } else { |
114 | 6.78k | z = x + 4*pio2_1; |
115 | 6.78k | y[0] = z + 4*pio2_1t; |
116 | 6.78k | y[1] = (z-y[0])+4*pio2_1t; |
117 | 6.78k | return -4; |
118 | 6.78k | } |
119 | 8.45k | } |
120 | 16.1k | } |
121 | 105k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ |
122 | 96.2k | medium: |
123 | 96.2k | fn = rnint((double_t)x*invpio2); |
124 | 96.2k | n = irint(fn); |
125 | 96.2k | r = x-fn*pio2_1; |
126 | 96.2k | w = fn*pio2_1t; /* 1st round good to 85 bit */ |
127 | 96.2k | { |
128 | 96.2k | u_int32_t high; |
129 | 96.2k | j = ix>>20; |
130 | 96.2k | y[0] = r-w; |
131 | 96.2k | GET_HIGH_WORD(high,y[0]); |
132 | 96.2k | i = j-((high>>20)&0x7ff); |
133 | 96.2k | if(i>16) { /* 2nd iteration needed, good to 118 */ |
134 | 2.58k | t = r; |
135 | 2.58k | w = fn*pio2_2; |
136 | 2.58k | r = t-w; |
137 | 2.58k | w = fn*pio2_2t-((t-r)-w); |
138 | 2.58k | y[0] = r-w; |
139 | 2.58k | GET_HIGH_WORD(high,y[0]); |
140 | 2.58k | i = j-((high>>20)&0x7ff); |
141 | 2.58k | 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 | 2.58k | } |
149 | 96.2k | } |
150 | 96.2k | y[1] = (r-y[0])-w; |
151 | 96.2k | return n; |
152 | 96.2k | } |
153 | | /* |
154 | | * all other (large) arguments |
155 | | */ |
156 | 9.29k | 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 | 9.29k | GET_LOW_WORD(low,x); |
161 | 9.29k | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ |
162 | 9.29k | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); |
163 | 27.8k | for(i=0;i<2;i++) { |
164 | 18.5k | tx[i] = (double)((int32_t)(z)); |
165 | 18.5k | z = (z-tx[i])*two24; |
166 | 18.5k | } |
167 | 9.29k | tx[2] = z; |
168 | 9.29k | nx = 3; |
169 | 20.6k | while(tx[nx-1]==zero) nx--; /* skip zero term */ |
170 | 9.29k | n = __kernel_rem_pio2(tx,ty,e0,nx,1); |
171 | 9.29k | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} |
172 | 3.97k | y[0] = ty[0]; y[1] = ty[1]; return n; |
173 | 9.29k | } Unexecuted instantiation: __ieee754_rem_pio2 s_cos.c:__ieee754_rem_pio2 Line | Count | Source | 49 | 251k | { | 50 | 251k | double z,w,t,r,fn; | 51 | 251k | double tx[3],ty[2]; | 52 | 251k | int32_t e0,i,j,nx,n,ix,hx; | 53 | 251k | u_int32_t low; | 54 | | | 55 | 251k | GET_HIGH_WORD(hx,x); /* high word of x */ | 56 | 251k | 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 | 251k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ | 62 | 163k | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ | 63 | 0 | goto medium; /* cancellation -- use medium case */ | 64 | 163k | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ | 65 | 156k | if (hx > 0) { | 66 | 150k | z = x - pio2_1; /* one round good to 85 bits */ | 67 | 150k | y[0] = z - pio2_1t; | 68 | 150k | y[1] = (z-y[0])-pio2_1t; | 69 | 150k | return 1; | 70 | 150k | } else { | 71 | 6.46k | z = x + pio2_1; | 72 | 6.46k | y[0] = z + pio2_1t; | 73 | 6.46k | y[1] = (z-y[0])+pio2_1t; | 74 | 6.46k | return -1; | 75 | 6.46k | } | 76 | 156k | } else { | 77 | 7.04k | if (hx > 0) { | 78 | 790 | z = x - 2*pio2_1; | 79 | 790 | y[0] = z - 2*pio2_1t; | 80 | 790 | y[1] = (z-y[0])-2*pio2_1t; | 81 | 790 | return 2; | 82 | 6.25k | } else { | 83 | 6.25k | z = x + 2*pio2_1; | 84 | 6.25k | y[0] = z + 2*pio2_1t; | 85 | 6.25k | y[1] = (z-y[0])+2*pio2_1t; | 86 | 6.25k | return -2; | 87 | 6.25k | } | 88 | 7.04k | } | 89 | 163k | } | 90 | 87.9k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ | 91 | 10.4k | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ | 92 | 3.92k | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ | 93 | 0 | goto medium; | 94 | 3.92k | if (hx > 0) { | 95 | 573 | z = x - 3*pio2_1; | 96 | 573 | y[0] = z - 3*pio2_1t; | 97 | 573 | y[1] = (z-y[0])-3*pio2_1t; | 98 | 573 | return 3; | 99 | 3.34k | } else { | 100 | 3.34k | z = x + 3*pio2_1; | 101 | 3.34k | y[0] = z + 3*pio2_1t; | 102 | 3.34k | y[1] = (z-y[0])+3*pio2_1t; | 103 | 3.34k | return -3; | 104 | 3.34k | } | 105 | 6.52k | } else { | 106 | 6.52k | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ | 107 | 0 | goto medium; | 108 | 6.52k | if (hx > 0) { | 109 | 384 | z = x - 4*pio2_1; | 110 | 384 | y[0] = z - 4*pio2_1t; | 111 | 384 | y[1] = (z-y[0])-4*pio2_1t; | 112 | 384 | return 4; | 113 | 6.14k | } else { | 114 | 6.14k | z = x + 4*pio2_1; | 115 | 6.14k | y[0] = z + 4*pio2_1t; | 116 | 6.14k | y[1] = (z-y[0])+4*pio2_1t; | 117 | 6.14k | return -4; | 118 | 6.14k | } | 119 | 6.52k | } | 120 | 10.4k | } | 121 | 77.5k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ | 122 | 76.4k | medium: | 123 | 76.4k | fn = rnint((double_t)x*invpio2); | 124 | 76.4k | n = irint(fn); | 125 | 76.4k | r = x-fn*pio2_1; | 126 | 76.4k | w = fn*pio2_1t; /* 1st round good to 85 bit */ | 127 | 76.4k | { | 128 | 76.4k | u_int32_t high; | 129 | 76.4k | j = ix>>20; | 130 | 76.4k | y[0] = r-w; | 131 | 76.4k | GET_HIGH_WORD(high,y[0]); | 132 | 76.4k | i = j-((high>>20)&0x7ff); | 133 | 76.4k | if(i>16) { /* 2nd iteration needed, good to 118 */ | 134 | 260 | t = r; | 135 | 260 | w = fn*pio2_2; | 136 | 260 | r = t-w; | 137 | 260 | w = fn*pio2_2t-((t-r)-w); | 138 | 260 | y[0] = r-w; | 139 | 260 | GET_HIGH_WORD(high,y[0]); | 140 | 260 | i = j-((high>>20)&0x7ff); | 141 | 260 | 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 | 260 | } | 149 | 76.4k | } | 150 | 76.4k | y[1] = (r-y[0])-w; | 151 | 76.4k | return n; | 152 | 76.4k | } | 153 | | /* | 154 | | * all other (large) arguments | 155 | | */ | 156 | 1.07k | 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 | 1.07k | GET_LOW_WORD(low,x); | 161 | 1.07k | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ | 162 | 1.07k | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); | 163 | 3.22k | for(i=0;i<2;i++) { | 164 | 2.15k | tx[i] = (double)((int32_t)(z)); | 165 | 2.15k | z = (z-tx[i])*two24; | 166 | 2.15k | } | 167 | 1.07k | tx[2] = z; | 168 | 1.07k | nx = 3; | 169 | 1.72k | while(tx[nx-1]==zero) nx--; /* skip zero term */ | 170 | 1.07k | n = __kernel_rem_pio2(tx,ty,e0,nx,1); | 171 | 1.07k | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} | 172 | 527 | y[0] = ty[0]; y[1] = ty[1]; return n; | 173 | 1.07k | } |
s_sin.c:__ieee754_rem_pio2 Line | Count | Source | 49 | 17.1k | { | 50 | 17.1k | double z,w,t,r,fn; | 51 | 17.1k | double tx[3],ty[2]; | 52 | 17.1k | int32_t e0,i,j,nx,n,ix,hx; | 53 | 17.1k | u_int32_t low; | 54 | | | 55 | 17.1k | GET_HIGH_WORD(hx,x); /* high word of x */ | 56 | 17.1k | 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 | 17.1k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ | 62 | 6.36k | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ | 63 | 0 | goto medium; /* cancellation -- use medium case */ | 64 | 6.36k | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ | 65 | 3.30k | if (hx > 0) { | 66 | 2.65k | z = x - pio2_1; /* one round good to 85 bits */ | 67 | 2.65k | y[0] = z - pio2_1t; | 68 | 2.65k | y[1] = (z-y[0])-pio2_1t; | 69 | 2.65k | return 1; | 70 | 2.65k | } else { | 71 | 648 | z = x + pio2_1; | 72 | 648 | y[0] = z + pio2_1t; | 73 | 648 | y[1] = (z-y[0])+pio2_1t; | 74 | 648 | return -1; | 75 | 648 | } | 76 | 3.30k | } else { | 77 | 3.05k | if (hx > 0) { | 78 | 1.83k | z = x - 2*pio2_1; | 79 | 1.83k | y[0] = z - 2*pio2_1t; | 80 | 1.83k | y[1] = (z-y[0])-2*pio2_1t; | 81 | 1.83k | return 2; | 82 | 1.83k | } else { | 83 | 1.22k | z = x + 2*pio2_1; | 84 | 1.22k | y[0] = z + 2*pio2_1t; | 85 | 1.22k | y[1] = (z-y[0])+2*pio2_1t; | 86 | 1.22k | return -2; | 87 | 1.22k | } | 88 | 3.05k | } | 89 | 6.36k | } | 90 | 10.8k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ | 91 | 5.29k | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ | 92 | 3.58k | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ | 93 | 0 | goto medium; | 94 | 3.58k | if (hx > 0) { | 95 | 1.22k | z = x - 3*pio2_1; | 96 | 1.22k | y[0] = z - 3*pio2_1t; | 97 | 1.22k | y[1] = (z-y[0])-3*pio2_1t; | 98 | 1.22k | return 3; | 99 | 2.35k | } else { | 100 | 2.35k | z = x + 3*pio2_1; | 101 | 2.35k | y[0] = z + 3*pio2_1t; | 102 | 2.35k | y[1] = (z-y[0])+3*pio2_1t; | 103 | 2.35k | return -3; | 104 | 2.35k | } | 105 | 3.58k | } else { | 106 | 1.71k | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ | 107 | 0 | goto medium; | 108 | 1.71k | if (hx > 0) { | 109 | 1.17k | z = x - 4*pio2_1; | 110 | 1.17k | y[0] = z - 4*pio2_1t; | 111 | 1.17k | y[1] = (z-y[0])-4*pio2_1t; | 112 | 1.17k | return 4; | 113 | 1.17k | } else { | 114 | 538 | z = x + 4*pio2_1; | 115 | 538 | y[0] = z + 4*pio2_1t; | 116 | 538 | y[1] = (z-y[0])+4*pio2_1t; | 117 | 538 | return -4; | 118 | 538 | } | 119 | 1.71k | } | 120 | 5.29k | } | 121 | 5.51k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ | 122 | 2.37k | medium: | 123 | 2.37k | fn = rnint((double_t)x*invpio2); | 124 | 2.37k | n = irint(fn); | 125 | 2.37k | r = x-fn*pio2_1; | 126 | 2.37k | w = fn*pio2_1t; /* 1st round good to 85 bit */ | 127 | 2.37k | { | 128 | 2.37k | u_int32_t high; | 129 | 2.37k | j = ix>>20; | 130 | 2.37k | y[0] = r-w; | 131 | 2.37k | GET_HIGH_WORD(high,y[0]); | 132 | 2.37k | i = j-((high>>20)&0x7ff); | 133 | 2.37k | if(i>16) { /* 2nd iteration needed, good to 118 */ | 134 | 329 | t = r; | 135 | 329 | w = fn*pio2_2; | 136 | 329 | r = t-w; | 137 | 329 | w = fn*pio2_2t-((t-r)-w); | 138 | 329 | y[0] = r-w; | 139 | 329 | GET_HIGH_WORD(high,y[0]); | 140 | 329 | i = j-((high>>20)&0x7ff); | 141 | 329 | 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 | 329 | } | 149 | 2.37k | } | 150 | 2.37k | y[1] = (r-y[0])-w; | 151 | 2.37k | return n; | 152 | 2.37k | } | 153 | | /* | 154 | | * all other (large) arguments | 155 | | */ | 156 | 3.13k | 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 | 3.13k | GET_LOW_WORD(low,x); | 161 | 3.13k | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ | 162 | 3.13k | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); | 163 | 9.40k | for(i=0;i<2;i++) { | 164 | 6.26k | tx[i] = (double)((int32_t)(z)); | 165 | 6.26k | z = (z-tx[i])*two24; | 166 | 6.26k | } | 167 | 3.13k | tx[2] = z; | 168 | 3.13k | nx = 3; | 169 | 8.39k | while(tx[nx-1]==zero) nx--; /* skip zero term */ | 170 | 3.13k | n = __kernel_rem_pio2(tx,ty,e0,nx,1); | 171 | 3.13k | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} | 172 | 1.51k | y[0] = ty[0]; y[1] = ty[1]; return n; | 173 | 3.13k | } |
s_tan.c:__ieee754_rem_pio2 Line | Count | Source | 49 | 23.7k | { | 50 | 23.7k | double z,w,t,r,fn; | 51 | 23.7k | double tx[3],ty[2]; | 52 | 23.7k | int32_t e0,i,j,nx,n,ix,hx; | 53 | 23.7k | u_int32_t low; | 54 | | | 55 | 23.7k | GET_HIGH_WORD(hx,x); /* high word of x */ | 56 | 23.7k | 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 | 23.7k | if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ | 62 | 801 | if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ | 63 | 0 | goto medium; /* cancellation -- use medium case */ | 64 | 801 | if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ | 65 | 617 | if (hx > 0) { | 66 | 363 | z = x - pio2_1; /* one round good to 85 bits */ | 67 | 363 | y[0] = z - pio2_1t; | 68 | 363 | y[1] = (z-y[0])-pio2_1t; | 69 | 363 | return 1; | 70 | 363 | } else { | 71 | 254 | z = x + pio2_1; | 72 | 254 | y[0] = z + pio2_1t; | 73 | 254 | y[1] = (z-y[0])+pio2_1t; | 74 | 254 | return -1; | 75 | 254 | } | 76 | 617 | } else { | 77 | 184 | if (hx > 0) { | 78 | 62 | z = x - 2*pio2_1; | 79 | 62 | y[0] = z - 2*pio2_1t; | 80 | 62 | y[1] = (z-y[0])-2*pio2_1t; | 81 | 62 | return 2; | 82 | 122 | } else { | 83 | 122 | z = x + 2*pio2_1; | 84 | 122 | y[0] = z + 2*pio2_1t; | 85 | 122 | y[1] = (z-y[0])+2*pio2_1t; | 86 | 122 | return -2; | 87 | 122 | } | 88 | 184 | } | 89 | 801 | } | 90 | 22.9k | if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ | 91 | 422 | if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ | 92 | 212 | if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ | 93 | 0 | goto medium; | 94 | 212 | if (hx > 0) { | 95 | 99 | z = x - 3*pio2_1; | 96 | 99 | y[0] = z - 3*pio2_1t; | 97 | 99 | y[1] = (z-y[0])-3*pio2_1t; | 98 | 99 | return 3; | 99 | 113 | } else { | 100 | 113 | z = x + 3*pio2_1; | 101 | 113 | y[0] = z + 3*pio2_1t; | 102 | 113 | y[1] = (z-y[0])+3*pio2_1t; | 103 | 113 | return -3; | 104 | 113 | } | 105 | 212 | } else { | 106 | 210 | if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ | 107 | 0 | goto medium; | 108 | 210 | if (hx > 0) { | 109 | 101 | z = x - 4*pio2_1; | 110 | 101 | y[0] = z - 4*pio2_1t; | 111 | 101 | y[1] = (z-y[0])-4*pio2_1t; | 112 | 101 | return 4; | 113 | 109 | } else { | 114 | 109 | z = x + 4*pio2_1; | 115 | 109 | y[0] = z + 4*pio2_1t; | 116 | 109 | y[1] = (z-y[0])+4*pio2_1t; | 117 | 109 | return -4; | 118 | 109 | } | 119 | 210 | } | 120 | 422 | } | 121 | 22.5k | if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ | 122 | 17.4k | medium: | 123 | 17.4k | fn = rnint((double_t)x*invpio2); | 124 | 17.4k | n = irint(fn); | 125 | 17.4k | r = x-fn*pio2_1; | 126 | 17.4k | w = fn*pio2_1t; /* 1st round good to 85 bit */ | 127 | 17.4k | { | 128 | 17.4k | u_int32_t high; | 129 | 17.4k | j = ix>>20; | 130 | 17.4k | y[0] = r-w; | 131 | 17.4k | GET_HIGH_WORD(high,y[0]); | 132 | 17.4k | i = j-((high>>20)&0x7ff); | 133 | 17.4k | if(i>16) { /* 2nd iteration needed, good to 118 */ | 134 | 1.99k | t = r; | 135 | 1.99k | w = fn*pio2_2; | 136 | 1.99k | r = t-w; | 137 | 1.99k | w = fn*pio2_2t-((t-r)-w); | 138 | 1.99k | y[0] = r-w; | 139 | 1.99k | GET_HIGH_WORD(high,y[0]); | 140 | 1.99k | i = j-((high>>20)&0x7ff); | 141 | 1.99k | 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 | 1.99k | } | 149 | 17.4k | } | 150 | 17.4k | y[1] = (r-y[0])-w; | 151 | 17.4k | return n; | 152 | 17.4k | } | 153 | | /* | 154 | | * all other (large) arguments | 155 | | */ | 156 | 5.08k | 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 | 5.08k | GET_LOW_WORD(low,x); | 161 | 5.08k | e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ | 162 | 5.08k | INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low); | 163 | 15.2k | for(i=0;i<2;i++) { | 164 | 10.1k | tx[i] = (double)((int32_t)(z)); | 165 | 10.1k | z = (z-tx[i])*two24; | 166 | 10.1k | } | 167 | 5.08k | tx[2] = z; | 168 | 5.08k | nx = 3; | 169 | 10.4k | while(tx[nx-1]==zero) nx--; /* skip zero term */ | 170 | 5.08k | n = __kernel_rem_pio2(tx,ty,e0,nx,1); | 171 | 5.08k | if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} | 172 | 1.93k | y[0] = ty[0]; y[1] = ty[1]; return n; | 173 | 5.08k | } |
|