5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25 /*
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 #pragma weak __cpow = cpow
31
32 /* INDENT OFF */
33 /*
34 * dcomplex cpow(dcomplex z);
35 *
36 * z**w analytically equivalent to
37 *
38 * cpow(z,w) = cexp(w clog(z))
39 *
40 * Let z = x+iy, w = u+iv.
41 * Since
42 * _________
43 * / 2 2 -1 y
44 * log(x+iy) = log(\/ x + y ) + i tan (---)
45 * x
46 *
47 * 1 2 2 -1 y
48 * = --- log(x + y ) + i tan (---)
49 * 2 x
50 * u 2 2 -1 y
51 * (u+iv)* log(x+iy) = --- log(x + y ) - v tan (---) + (1)
52 * 2 x
69 * 1. (anything) ** 0 is 1
70 * 2. (anything) ** 1 is itself
71 * 3. When v = 0, y = 0:
72 * If x is finite and negative, and u is finite, then
73 * x ** u = exp(u*pi i) * pow(|x|, u);
74 * otherwise,
75 * x ** u = pow(x, u);
76 * 4. When v = 0, x = 0 or |x| = |y| or x is inf or y is inf:
77 * (x + y i) ** u = r * exp(q i)
78 * where
79 * r = hypot(x,y) ** u
80 * q = u * atan2pi(y, x)
81 *
82 * 5. otherwise, z**w is NAN if any x, y, u, v is a Nan or inf
83 *
84 * Note: many results of special cases are obtained in terms of
85 * polar coordinate. In the conversion from polar to rectangle:
86 * r exp(q i) = r * cos(q) + r * sin(q) i,
87 * we regard r * 0 is 0 except when r is a NaN.
88 */
89 /* INDENT ON */
90
91 #include "libm.h" /* atan2/exp/fabs/hypot/log/pow/scalbn */
92 /* atan2pi/exp2/sincos/sincospi/__k_clog_r/__k_atan2 */
93 #include "complex_wrapper.h"
94
95 extern void sincospi(double, double *, double *);
96
97 static const double
98 huge = 1e300,
99 tiny = 1e-300,
100 invln2 = 1.44269504088896338700e+00,
101 ln2hi = 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
102 ln2lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
103 one = 1.0,
104 zero = 0.0;
105
106 static const int hiinf = 0x7ff00000;
107 extern double atan2pi(double, double);
108
109 /*
110 * Assuming |t[0]| > |t[1]| and |t[2]| > |t[3]|, sum4fp subroutine
111 * compute t[0] + t[1] + t[2] + t[3] into two double fp numbers.
112 */
113 static double
114 sum4fp(double ta[], double *w) {
115 double t1, t2, t3, t4, w1, w2, t;
116 t1 = ta[0]; t2 = ta[1]; t3 = ta[2]; t4 = ta[3];
117 /*
118 * Rearrange ti so that |t1| >= |t2| >= |t3| >= |t4|
119 */
120 if (fabs(t4) > fabs(t1)) {
121 t = t1; t1 = t3; t3 = t;
122 t = t2; t2 = t4; t4 = t;
123 } else if (fabs(t3) > fabs(t1)) {
124 t = t1; t1 = t3;
125 if (fabs(t4) > fabs(t2)) {
126 t3 = t4; t4 = t2; t2 = t;
127 } else {
128 t3 = t2; t2 = t;
129 }
130 } else if (fabs(t3) > fabs(t2)) {
131 t = t2; t2 = t3;
132 if (fabs(t4) > fabs(t2)) {
133 t3 = t4; t4 = t;
134 } else
135 t3 = t;
136 }
137 /* summing r = t1 + t2 + t3 + t4 to w1 + w2 */
138 w1 = t3 + t4;
139 w2 = t4 - (w1 - t3);
140 t = t2 + w1;
141 w2 += w1 - (t - t2);
142 w1 = t + w2;
143 w2 += t - w1;
144 t = t1 + w1;
145 w2 += w1 - (t - t1);
146 w1 = t + w2;
147 *w = w2 - (w1 - t);
148 return (w1);
149 }
150
151 dcomplex
152 cpow(dcomplex z, dcomplex w) {
153 dcomplex ans;
154 double x, y, u, v, t, c, s, r, x2, y2;
155 double b[4], t1, t2, t3, t4, w1, w2, u1, v1, x1, y1;
156 int ix, iy, hx, lx, hy, ly, hv, hu, iu, iv, lu, lv;
157 int i, j, k;
158
159 x = D_RE(z);
160 y = D_IM(z);
161 u = D_RE(w);
162 v = D_IM(w);
163 hx = ((int *) &x)[HIWORD];
164 lx = ((int *) &x)[LOWORD];
165 hy = ((int *) &y)[HIWORD];
166 ly = ((int *) &y)[LOWORD];
167 hu = ((int *) &u)[HIWORD];
168 lu = ((int *) &u)[LOWORD];
169 hv = ((int *) &v)[HIWORD];
170 lv = ((int *) &v)[LOWORD];
171 ix = hx & 0x7fffffff;
172 iy = hy & 0x7fffffff;
173 iu = hu & 0x7fffffff;
174 iv = hv & 0x7fffffff;
175
176 j = 0;
177 if ((iv | lv) == 0) { /* z**(real) */
178 if (((hu - 0x3ff00000) | lu) == 0) { /* z ** 1 = z */
179 D_RE(ans) = x;
180 D_IM(ans) = y;
181 } else if ((iu | lu) == 0) { /* z ** 0 = 1 */
182 D_RE(ans) = one;
183 D_IM(ans) = zero;
184 } else if ((iy | ly) == 0) { /* (real)**(real) */
185 D_IM(ans) = zero;
186 if (hx < 0 && ix < hiinf && iu < hiinf) {
187 /* -x ** u is exp(i*pi*u)*pow(x,u) */
188 r = pow(-x, u);
189 sincospi(u, &s, &c);
190 D_RE(ans) = (c == zero)? c: c * r;
191 D_IM(ans) = (s == zero)? s: s * r;
192 } else
193 D_RE(ans) = pow(x, u);
194 } else if (((ix | lx) == 0) || ix >= hiinf || iy >= hiinf) {
195 if (isnan(x) || isnan(y) || isnan(u))
196 D_RE(ans) = D_IM(ans) = x + y + u;
197 else {
198 if ((ix | lx) == 0)
199 r = fabs(y);
200 else
201 r = fabs(x) + fabs(y);
202 t = atan2pi(y, x);
203 sincospi(t * u, &s, &c);
204 D_RE(ans) = (c == zero)? c: c * r;
205 D_IM(ans) = (s == zero)? s: s * r;
206 }
207 } else if (((ix - iy) | (lx - ly)) == 0) { /* |x| = |y| */
208 if (hx >= 0) {
209 t = (hy >= 0)? 0.25 : -0.25;
210 sincospi(t * u, &s, &c);
211 } else if ((lu & 3) == 0) {
212 t = (hy >= 0)? 0.75 : -0.75;
213 sincospi(t * u, &s, &c);
214 } else {
215 r = (hy >= 0)? u : -u;
216 t = -0.25 * r;
217 w1 = r + t;
218 w2 = t - (w1 - r);
219 sincospi(w1, &t1, &t2);
220 sincospi(w2, &t3, &t4);
221 s = t1 * t4 + t3 * t2;
222 c = t2 * t4 - t1 * t3;
223 }
224 if (ix < 0x3fe00000) /* |x| < 1/2 */
225 r = pow(fabs(x + x), u) * exp2(-0.5 * u);
226 else if (ix >= 0x3ff00000 || iu < 0x408ff800)
227 /* |x| >= 1 or |u| < 1023 */
228 r = pow(fabs(x), u) * exp2(0.5 * u);
229 else /* special treatment */
230 j = 2;
231 if (j == 0) {
232 D_RE(ans) = (c == zero)? c: c * r;
233 D_IM(ans) = (s == zero)? s: s * r;
234 }
235 } else
236 j = 1;
237 if (j == 0)
238 return (ans);
239 }
240 if (iu >= hiinf || iv >= hiinf || ix >= hiinf || iy >= hiinf) {
241 /*
242 * non-zero imag part(s) with inf component(s) yields NaN
243 */
244 t = fabs(x) + fabs(y) + fabs(u) + fabs(v);
245 D_RE(ans) = D_IM(ans) = t - t;
246 } else {
247 k = 0; /* no scaling */
248 if (iu > 0x7f000000 || iv > 0x7f000000) {
249 u *= .0009765625; /* scale 2**-10 to avoid overflow */
250 v *= .0009765625;
251 k = 1; /* scale by 2**-10 */
252 }
253 /*
254 * Use similated higher precision arithmetic to compute:
255 * r = u * log(hypot(x, y)) - v * atan2(y, x)
256 * q = u * atan2(y, x) + v * log(hypot(x, y))
257 */
258 t1 = __k_clog_r(x, y, &t2);
259 t3 = __k_atan2(y, x, &t4);
260 x1 = t1;
261 y1 = t3;
262 u1 = u;
263 v1 = v;
264 ((int *) &u1)[LOWORD] &= 0xf8000000;
265 ((int *) &v1)[LOWORD] &= 0xf8000000;
266 ((int *) &x1)[LOWORD] &= 0xf8000000;
267 ((int *) &y1)[LOWORD] &= 0xf8000000;
268 x2 = t2 - (x1 - t1); /* log(hypot(x,y)) = x1 + x2 */
269 y2 = t4 - (y1 - t3); /* atan2(y,x) = y1 + y2 */
270 /* compute q = u * atan2(y, x) + v * log(hypot(x, y)) */
271 if (j != 2) {
272 b[0] = u1 * y1;
273 b[1] = (u - u1) * y1 + u * y2;
274 if (j == 1) { /* v = 0 */
275 w1 = b[0] + b[1];
276 w2 = b[1] - (w1 - b[0]);
277 } else {
278 b[2] = v1 * x1;
279 b[3] = (v - v1) * x1 + v * x2;
280 w1 = sum4fp(b, &w2);
281 }
282 sincos(w1, &t1, &t2);
283 sincos(w2, &t3, &t4);
284 s = t1 * t4 + t3 * t2;
285 c = t2 * t4 - t1 * t3;
286 if (k == 1)
287 /*
288 * square (cos(q) + i sin(q)) k times to get
289 * (cos(2^k * q + i sin(2^k * q)
290 */
291 for (i = 0; i < 10; i++) {
292 t1 = s * c;
293 c = (c + s) * (c - s);
294 s = t1 + t1;
295 }
296 }
297 /* compute r = u * (t1, t2) - v * (t3, t4) */
298 b[0] = u1 * x1;
299 b[1] = (u - u1) * x1 + u * x2;
300 if (j == 1) { /* v = 0 */
301 w1 = b[0] + b[1];
302 w2 = b[1] - (w1 - b[0]);
303 } else {
304 b[2] = -v1 * y1;
305 b[3] = (v1 - v) * y1 - v * y2;
306 w1 = sum4fp(b, &w2);
307 }
308 /* check over/underflow for exp(w1 + w2) */
309 if (k && fabs(w1) < 1000.0) {
310 w1 *= 1024; w2 *= 1024; k = 0;
311 }
312 hx = ((int *) &w1)[HIWORD];
313 lx = ((int *) &w1)[LOWORD];
314 ix = hx & 0x7fffffff;
315 /* compute exp(w1 + w2) */
316 if (ix < 0x3c900000) /* exp(tiny < 2**-54) = 1 */
317 r = one;
318 else if (ix >= 0x40880000) /* overflow/underflow */
319 r = (hx < 0)? tiny * tiny : huge * huge;
320 else { /* compute exp(w1 + w2) */
321 k = (int) (invln2 * w1 + ((hx >= 0)? 0.5 : -0.5));
322 t1 = (double) k;
323 t2 = w1 - t1 * ln2hi;
324 t3 = w2 - t1 * ln2lo;
325 r = exp(t2 + t3);
326 }
327 if (c != zero) c *= r;
328 if (s != zero) s *= r;
329 if (k != 0) {
330 c = scalbn(c, k);
331 s = scalbn(s, k);
332 }
333 D_RE(ans) = c;
334 D_IM(ans) = s;
335 }
336 return (ans);
337 }
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 /*
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma weak __cpow = cpow
32
33
34 /*
35 * dcomplex cpow(dcomplex z);
36 *
37 * z**w analytically equivalent to
38 *
39 * cpow(z,w) = cexp(w clog(z))
40 *
41 * Let z = x+iy, w = u+iv.
42 * Since
43 * _________
44 * / 2 2 -1 y
45 * log(x+iy) = log(\/ x + y ) + i tan (---)
46 * x
47 *
48 * 1 2 2 -1 y
49 * = --- log(x + y ) + i tan (---)
50 * 2 x
51 * u 2 2 -1 y
52 * (u+iv)* log(x+iy) = --- log(x + y ) - v tan (---) + (1)
53 * 2 x
70 * 1. (anything) ** 0 is 1
71 * 2. (anything) ** 1 is itself
72 * 3. When v = 0, y = 0:
73 * If x is finite and negative, and u is finite, then
74 * x ** u = exp(u*pi i) * pow(|x|, u);
75 * otherwise,
76 * x ** u = pow(x, u);
77 * 4. When v = 0, x = 0 or |x| = |y| or x is inf or y is inf:
78 * (x + y i) ** u = r * exp(q i)
79 * where
80 * r = hypot(x,y) ** u
81 * q = u * atan2pi(y, x)
82 *
83 * 5. otherwise, z**w is NAN if any x, y, u, v is a Nan or inf
84 *
85 * Note: many results of special cases are obtained in terms of
86 * polar coordinate. In the conversion from polar to rectangle:
87 * r exp(q i) = r * cos(q) + r * sin(q) i,
88 * we regard r * 0 is 0 except when r is a NaN.
89 */
90
91 /*
92 * atan2/exp/fabs/hypot/log/pow/scalbn
93 * atan2pi/exp2/sincos/sincospi/__k_clog_r/__k_atan2
94 */
95 #include "libm.h"
96 #include "complex_wrapper.h"
97
98 extern void sincospi(double, double *, double *);
99 static const double huge = 1e300,
100 tiny = 1e-300,
101 invln2 = 1.44269504088896338700e+00,
102 ln2hi = 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
103 ln2lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
104 one = 1.0,
105 zero = 0.0;
106 static const int hiinf = 0x7ff00000;
107 extern double atan2pi(double, double);
108
109 /*
110 * Assuming |t[0]| > |t[1]| and |t[2]| > |t[3]|, sum4fp subroutine
111 * compute t[0] + t[1] + t[2] + t[3] into two double fp numbers.
112 */
113 static double
114 sum4fp(double ta[], double *w)
115 {
116 double t1, t2, t3, t4, w1, w2, t;
117
118 t1 = ta[0];
119 t2 = ta[1];
120 t3 = ta[2];
121 t4 = ta[3];
122
123 /*
124 * Rearrange ti so that |t1| >= |t2| >= |t3| >= |t4|
125 */
126 if (fabs(t4) > fabs(t1)) {
127 t = t1;
128 t1 = t3;
129 t3 = t;
130 t = t2;
131 t2 = t4;
132 t4 = t;
133 } else if (fabs(t3) > fabs(t1)) {
134 t = t1;
135 t1 = t3;
136
137 if (fabs(t4) > fabs(t2)) {
138 t3 = t4;
139 t4 = t2;
140 t2 = t;
141 } else {
142 t3 = t2;
143 t2 = t;
144 }
145 } else if (fabs(t3) > fabs(t2)) {
146 t = t2;
147 t2 = t3;
148
149 if (fabs(t4) > fabs(t2)) {
150 t3 = t4;
151 t4 = t;
152 } else {
153 t3 = t;
154 }
155 }
156
157 /* summing r = t1 + t2 + t3 + t4 to w1 + w2 */
158 w1 = t3 + t4;
159 w2 = t4 - (w1 - t3);
160 t = t2 + w1;
161 w2 += w1 - (t - t2);
162 w1 = t + w2;
163 w2 += t - w1;
164 t = t1 + w1;
165 w2 += w1 - (t - t1);
166 w1 = t + w2;
167 *w = w2 - (w1 - t);
168 return (w1);
169 }
170
171 dcomplex
172 cpow(dcomplex z, dcomplex w)
173 {
174 dcomplex ans;
175 double x, y, u, v, t, c, s, r, x2, y2;
176 double b[4], t1, t2, t3, t4, w1, w2, u1, v1, x1, y1;
177 int ix, iy, hx, lx, hy, ly, hv, hu, iu, iv, lu, lv;
178 int i, j, k;
179
180 x = D_RE(z);
181 y = D_IM(z);
182 u = D_RE(w);
183 v = D_IM(w);
184 hx = ((int *)&x)[HIWORD];
185 lx = ((int *)&x)[LOWORD];
186 hy = ((int *)&y)[HIWORD];
187 ly = ((int *)&y)[LOWORD];
188 hu = ((int *)&u)[HIWORD];
189 lu = ((int *)&u)[LOWORD];
190 hv = ((int *)&v)[HIWORD];
191 lv = ((int *)&v)[LOWORD];
192 ix = hx & 0x7fffffff;
193 iy = hy & 0x7fffffff;
194 iu = hu & 0x7fffffff;
195 iv = hv & 0x7fffffff;
196
197 j = 0;
198
199 if ((iv | lv) == 0) { /* z**(real) */
200 if (((hu - 0x3ff00000) | lu) == 0) { /* z ** 1 = z */
201 D_RE(ans) = x;
202 D_IM(ans) = y;
203 } else if ((iu | lu) == 0) { /* z ** 0 = 1 */
204 D_RE(ans) = one;
205 D_IM(ans) = zero;
206 } else if ((iy | ly) == 0) { /* (real)**(real) */
207 D_IM(ans) = zero;
208
209 if (hx < 0 && ix < hiinf && iu < hiinf) {
210 /* -x ** u is exp(i*pi*u)*pow(x,u) */
211 r = pow(-x, u);
212 sincospi(u, &s, &c);
213 D_RE(ans) = (c == zero) ? c : c *r;
214 D_IM(ans) = (s == zero) ? s : s *r;
215 } else {
216 D_RE(ans) = pow(x, u);
217 }
218 } else if (((ix | lx) == 0) || ix >= hiinf || iy >= hiinf) {
219 if (isnan(x) || isnan(y) || isnan(u)) {
220 D_RE(ans) = D_IM(ans) = x + y + u;
221 } else {
222 if ((ix | lx) == 0)
223 r = fabs(y);
224 else
225 r = fabs(x) + fabs(y);
226
227 t = atan2pi(y, x);
228 sincospi(t * u, &s, &c);
229 D_RE(ans) = (c == zero) ? c : c *r;
230 D_IM(ans) = (s == zero) ? s : s *r;
231 }
232 } else if (((ix - iy) | (lx - ly)) == 0) { /* |x| = |y| */
233 if (hx >= 0) {
234 t = (hy >= 0) ? 0.25 : -0.25;
235 sincospi(t * u, &s, &c);
236 } else if ((lu & 3) == 0) {
237 t = (hy >= 0) ? 0.75 : -0.75;
238 sincospi(t * u, &s, &c);
239 } else {
240 r = (hy >= 0) ? u : -u;
241 t = -0.25 * r;
242 w1 = r + t;
243 w2 = t - (w1 - r);
244 sincospi(w1, &t1, &t2);
245 sincospi(w2, &t3, &t4);
246 s = t1 * t4 + t3 * t2;
247 c = t2 * t4 - t1 * t3;
248 }
249
250 if (ix < 0x3fe00000) /* |x| < 1/2 */
251 r = pow(fabs(x + x), u) * exp2(-0.5 * u);
252 else if (ix >= 0x3ff00000 || iu < 0x408ff800)
253 /* |x| >= 1 or |u| < 1023 */
254 r = pow(fabs(x), u) * exp2(0.5 * u);
255 else /* special treatment */
256 j = 2;
257
258 if (j == 0) {
259 D_RE(ans) = (c == zero) ? c : c *r;
260 D_IM(ans) = (s == zero) ? s : s *r;
261 }
262 } else {
263 j = 1;
264 }
265
266 if (j == 0)
267 return (ans);
268 }
269
270 if (iu >= hiinf || iv >= hiinf || ix >= hiinf || iy >= hiinf) {
271 /*
272 * non-zero imag part(s) with inf component(s) yields NaN
273 */
274 t = fabs(x) + fabs(y) + fabs(u) + fabs(v);
275 D_RE(ans) = D_IM(ans) = t - t;
276 } else {
277 k = 0; /* no scaling */
278
279 if (iu > 0x7f000000 || iv > 0x7f000000) {
280 u *= .0009765625; /* scale 2**-10 to avoid overflow */
281 v *= .0009765625;
282 k = 1; /* scale by 2**-10 */
283 }
284
285 /*
286 * Use similated higher precision arithmetic to compute:
287 * r = u * log(hypot(x, y)) - v * atan2(y, x)
288 * q = u * atan2(y, x) + v * log(hypot(x, y))
289 */
290 t1 = __k_clog_r(x, y, &t2);
291 t3 = __k_atan2(y, x, &t4);
292 x1 = t1;
293 y1 = t3;
294 u1 = u;
295 v1 = v;
296 ((int *)&u1)[LOWORD] &= 0xf8000000;
297 ((int *)&v1)[LOWORD] &= 0xf8000000;
298 ((int *)&x1)[LOWORD] &= 0xf8000000;
299 ((int *)&y1)[LOWORD] &= 0xf8000000;
300 x2 = t2 - (x1 - t1); /* log(hypot(x,y)) = x1 + x2 */
301 y2 = t4 - (y1 - t3); /* atan2(y,x) = y1 + y2 */
302
303 /* compute q = u * atan2(y, x) + v * log(hypot(x, y)) */
304 if (j != 2) {
305 b[0] = u1 * y1;
306 b[1] = (u - u1) * y1 + u * y2;
307
308 if (j == 1) { /* v = 0 */
309 w1 = b[0] + b[1];
310 w2 = b[1] - (w1 - b[0]);
311 } else {
312 b[2] = v1 * x1;
313 b[3] = (v - v1) * x1 + v * x2;
314 w1 = sum4fp(b, &w2);
315 }
316
317 sincos(w1, &t1, &t2);
318 sincos(w2, &t3, &t4);
319 s = t1 * t4 + t3 * t2;
320 c = t2 * t4 - t1 * t3;
321
322 if (k == 1) {
323 /*
324 * square (cos(q) + i sin(q)) k times to get
325 * (cos(2^k * q + i sin(2^k * q)
326 */
327 for (i = 0; i < 10; i++) {
328 t1 = s * c;
329 c = (c + s) * (c - s);
330 s = t1 + t1;
331 }
332 }
333 }
334
335 /* compute r = u * (t1, t2) - v * (t3, t4) */
336 b[0] = u1 * x1;
337 b[1] = (u - u1) * x1 + u * x2;
338
339 if (j == 1) { /* v = 0 */
340 w1 = b[0] + b[1];
341 w2 = b[1] - (w1 - b[0]);
342 } else {
343 b[2] = -v1 * y1;
344 b[3] = (v1 - v) * y1 - v * y2;
345 w1 = sum4fp(b, &w2);
346 }
347
348 /* check over/underflow for exp(w1 + w2) */
349 if (k && fabs(w1) < 1000.0) {
350 w1 *= 1024;
351 w2 *= 1024;
352 k = 0;
353 }
354
355 hx = ((int *)&w1)[HIWORD];
356 lx = ((int *)&w1)[LOWORD];
357 ix = hx & 0x7fffffff;
358
359 /* compute exp(w1 + w2) */
360 if (ix < 0x3c900000) { /* exp(tiny < 2**-54) = 1 */
361 r = one;
362 } else if (ix >= 0x40880000) { /* overflow/underflow */
363 r = (hx < 0) ? tiny * tiny : huge * huge;
364 } else { /* compute exp(w1 + w2) */
365 k = (int)(invln2 * w1 + ((hx >= 0) ? 0.5 : -0.5));
366 t1 = (double)k;
367 t2 = w1 - t1 * ln2hi;
368 t3 = w2 - t1 * ln2lo;
369 r = exp(t2 + t3);
370 }
371
372 if (c != zero)
373 c *= r;
374
375 if (s != zero)
376 s *= r;
377
378 if (k != 0) {
379 c = scalbn(c, k);
380 s = scalbn(s, k);
381 }
382
383 D_RE(ans) = c;
384 D_IM(ans) = s;
385 }
386
387 return (ans);
388 }
|