1*181254a7Smrg /*
2*181254a7Smrg * ====================================================
3*181254a7Smrg * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4*181254a7Smrg *
5*181254a7Smrg * Developed at SunPro, a Sun Microsystems, Inc. business.
6*181254a7Smrg * Permission to use, copy, modify, and distribute this
7*181254a7Smrg * software is freely granted, provided that this notice
8*181254a7Smrg * is preserved.
9*181254a7Smrg * ====================================================
10*181254a7Smrg */
11*181254a7Smrg
12*181254a7Smrg /* Expansions and modifications for 128-bit long double are
13*181254a7Smrg Copyright (C) 2001 Stephen L. Moshier <moshier@na-net.ornl.gov>
14*181254a7Smrg and are incorporated herein by permission of the author. The author
15*181254a7Smrg reserves the right to distribute this material elsewhere under different
16*181254a7Smrg copying permissions. These modifications are distributed here under
17*181254a7Smrg the following terms:
18*181254a7Smrg
19*181254a7Smrg This library is free software; you can redistribute it and/or
20*181254a7Smrg modify it under the terms of the GNU Lesser General Public
21*181254a7Smrg License as published by the Free Software Foundation; either
22*181254a7Smrg version 2.1 of the License, or (at your option) any later version.
23*181254a7Smrg
24*181254a7Smrg This library is distributed in the hope that it will be useful,
25*181254a7Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
26*181254a7Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27*181254a7Smrg Lesser General Public License for more details.
28*181254a7Smrg
29*181254a7Smrg You should have received a copy of the GNU Lesser General Public
30*181254a7Smrg License along with this library; if not, see
31*181254a7Smrg <http://www.gnu.org/licenses/>. */
32*181254a7Smrg
33*181254a7Smrg /* powq(x,y) return x**y
34*181254a7Smrg *
35*181254a7Smrg * n
36*181254a7Smrg * Method: Let x = 2 * (1+f)
37*181254a7Smrg * 1. Compute and return log2(x) in two pieces:
38*181254a7Smrg * log2(x) = w1 + w2,
39*181254a7Smrg * where w1 has 113-53 = 60 bit trailing zeros.
40*181254a7Smrg * 2. Perform y*log2(x) = n+y' by simulating muti-precision
41*181254a7Smrg * arithmetic, where |y'|<=0.5.
42*181254a7Smrg * 3. Return x**y = 2**n*exp(y'*log2)
43*181254a7Smrg *
44*181254a7Smrg * Special cases:
45*181254a7Smrg * 1. (anything) ** 0 is 1
46*181254a7Smrg * 2. (anything) ** 1 is itself
47*181254a7Smrg * 3. (anything) ** NAN is NAN
48*181254a7Smrg * 4. NAN ** (anything except 0) is NAN
49*181254a7Smrg * 5. +-(|x| > 1) ** +INF is +INF
50*181254a7Smrg * 6. +-(|x| > 1) ** -INF is +0
51*181254a7Smrg * 7. +-(|x| < 1) ** +INF is +0
52*181254a7Smrg * 8. +-(|x| < 1) ** -INF is +INF
53*181254a7Smrg * 9. +-1 ** +-INF is NAN
54*181254a7Smrg * 10. +0 ** (+anything except 0, NAN) is +0
55*181254a7Smrg * 11. -0 ** (+anything except 0, NAN, odd integer) is +0
56*181254a7Smrg * 12. +0 ** (-anything except 0, NAN) is +INF
57*181254a7Smrg * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
58*181254a7Smrg * 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
59*181254a7Smrg * 15. +INF ** (+anything except 0,NAN) is +INF
60*181254a7Smrg * 16. +INF ** (-anything except 0,NAN) is +0
61*181254a7Smrg * 17. -INF ** (anything) = -0 ** (-anything)
62*181254a7Smrg * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
63*181254a7Smrg * 19. (-anything except 0 and inf) ** (non-integer) is NAN
64*181254a7Smrg *
65*181254a7Smrg */
66*181254a7Smrg
67*181254a7Smrg #include "quadmath-imp.h"
68*181254a7Smrg
69*181254a7Smrg static const __float128 bp[] = {
70*181254a7Smrg 1,
71*181254a7Smrg 1.5Q,
72*181254a7Smrg };
73*181254a7Smrg
74*181254a7Smrg /* log_2(1.5) */
75*181254a7Smrg static const __float128 dp_h[] = {
76*181254a7Smrg 0.0,
77*181254a7Smrg 5.8496250072115607565592654282227158546448E-1Q
78*181254a7Smrg };
79*181254a7Smrg
80*181254a7Smrg /* Low part of log_2(1.5) */
81*181254a7Smrg static const __float128 dp_l[] = {
82*181254a7Smrg 0.0,
83*181254a7Smrg 1.0579781240112554492329533686862998106046E-16Q
84*181254a7Smrg };
85*181254a7Smrg
86*181254a7Smrg static const __float128 zero = 0,
87*181254a7Smrg one = 1,
88*181254a7Smrg two = 2,
89*181254a7Smrg two113 = 1.0384593717069655257060992658440192E34Q,
90*181254a7Smrg huge = 1.0e3000Q,
91*181254a7Smrg tiny = 1.0e-3000Q;
92*181254a7Smrg
93*181254a7Smrg /* 3/2 log x = 3 z + z^3 + z^3 (z^2 R(z^2))
94*181254a7Smrg z = (x-1)/(x+1)
95*181254a7Smrg 1 <= x <= 1.25
96*181254a7Smrg Peak relative error 2.3e-37 */
97*181254a7Smrg static const __float128 LN[] =
98*181254a7Smrg {
99*181254a7Smrg -3.0779177200290054398792536829702930623200E1Q,
100*181254a7Smrg 6.5135778082209159921251824580292116201640E1Q,
101*181254a7Smrg -4.6312921812152436921591152809994014413540E1Q,
102*181254a7Smrg 1.2510208195629420304615674658258363295208E1Q,
103*181254a7Smrg -9.9266909031921425609179910128531667336670E-1Q
104*181254a7Smrg };
105*181254a7Smrg static const __float128 LD[] =
106*181254a7Smrg {
107*181254a7Smrg -5.129862866715009066465422805058933131960E1Q,
108*181254a7Smrg 1.452015077564081884387441590064272782044E2Q,
109*181254a7Smrg -1.524043275549860505277434040464085593165E2Q,
110*181254a7Smrg 7.236063513651544224319663428634139768808E1Q,
111*181254a7Smrg -1.494198912340228235853027849917095580053E1Q
112*181254a7Smrg /* 1.0E0 */
113*181254a7Smrg };
114*181254a7Smrg
115*181254a7Smrg /* exp(x) = 1 + x - x / (1 - 2 / (x - x^2 R(x^2)))
116*181254a7Smrg 0 <= x <= 0.5
117*181254a7Smrg Peak relative error 5.7e-38 */
118*181254a7Smrg static const __float128 PN[] =
119*181254a7Smrg {
120*181254a7Smrg 5.081801691915377692446852383385968225675E8Q,
121*181254a7Smrg 9.360895299872484512023336636427675327355E6Q,
122*181254a7Smrg 4.213701282274196030811629773097579432957E4Q,
123*181254a7Smrg 5.201006511142748908655720086041570288182E1Q,
124*181254a7Smrg 9.088368420359444263703202925095675982530E-3Q,
125*181254a7Smrg };
126*181254a7Smrg static const __float128 PD[] =
127*181254a7Smrg {
128*181254a7Smrg 3.049081015149226615468111430031590411682E9Q,
129*181254a7Smrg 1.069833887183886839966085436512368982758E8Q,
130*181254a7Smrg 8.259257717868875207333991924545445705394E5Q,
131*181254a7Smrg 1.872583833284143212651746812884298360922E3Q,
132*181254a7Smrg /* 1.0E0 */
133*181254a7Smrg };
134*181254a7Smrg
135*181254a7Smrg static const __float128
136*181254a7Smrg /* ln 2 */
137*181254a7Smrg lg2 = 6.9314718055994530941723212145817656807550E-1Q,
138*181254a7Smrg lg2_h = 6.9314718055994528622676398299518041312695E-1Q,
139*181254a7Smrg lg2_l = 2.3190468138462996154948554638754786504121E-17Q,
140*181254a7Smrg ovt = 8.0085662595372944372e-0017Q,
141*181254a7Smrg /* 2/(3*log(2)) */
142*181254a7Smrg cp = 9.6179669392597560490661645400126142495110E-1Q,
143*181254a7Smrg cp_h = 9.6179669392597555432899980587535537779331E-1Q,
144*181254a7Smrg cp_l = 5.0577616648125906047157785230014751039424E-17Q;
145*181254a7Smrg
146*181254a7Smrg __float128
powq(__float128 x,__float128 y)147*181254a7Smrg powq (__float128 x, __float128 y)
148*181254a7Smrg {
149*181254a7Smrg __float128 z, ax, z_h, z_l, p_h, p_l;
150*181254a7Smrg __float128 y1, t1, t2, r, s, sgn, t, u, v, w;
151*181254a7Smrg __float128 s2, s_h, s_l, t_h, t_l, ay;
152*181254a7Smrg int32_t i, j, k, yisint, n;
153*181254a7Smrg uint32_t ix, iy;
154*181254a7Smrg int32_t hx, hy;
155*181254a7Smrg ieee854_float128 o, p, q;
156*181254a7Smrg
157*181254a7Smrg p.value = x;
158*181254a7Smrg hx = p.words32.w0;
159*181254a7Smrg ix = hx & 0x7fffffff;
160*181254a7Smrg
161*181254a7Smrg q.value = y;
162*181254a7Smrg hy = q.words32.w0;
163*181254a7Smrg iy = hy & 0x7fffffff;
164*181254a7Smrg
165*181254a7Smrg
166*181254a7Smrg /* y==zero: x**0 = 1 */
167*181254a7Smrg if ((iy | q.words32.w1 | q.words32.w2 | q.words32.w3) == 0
168*181254a7Smrg && !issignalingq (x))
169*181254a7Smrg return one;
170*181254a7Smrg
171*181254a7Smrg /* 1.0**y = 1; -1.0**+-Inf = 1 */
172*181254a7Smrg if (x == one && !issignalingq (y))
173*181254a7Smrg return one;
174*181254a7Smrg if (x == -1 && iy == 0x7fff0000
175*181254a7Smrg && (q.words32.w1 | q.words32.w2 | q.words32.w3) == 0)
176*181254a7Smrg return one;
177*181254a7Smrg
178*181254a7Smrg /* +-NaN return x+y */
179*181254a7Smrg if ((ix > 0x7fff0000)
180*181254a7Smrg || ((ix == 0x7fff0000)
181*181254a7Smrg && ((p.words32.w1 | p.words32.w2 | p.words32.w3) != 0))
182*181254a7Smrg || (iy > 0x7fff0000)
183*181254a7Smrg || ((iy == 0x7fff0000)
184*181254a7Smrg && ((q.words32.w1 | q.words32.w2 | q.words32.w3) != 0)))
185*181254a7Smrg return x + y;
186*181254a7Smrg
187*181254a7Smrg /* determine if y is an odd int when x < 0
188*181254a7Smrg * yisint = 0 ... y is not an integer
189*181254a7Smrg * yisint = 1 ... y is an odd int
190*181254a7Smrg * yisint = 2 ... y is an even int
191*181254a7Smrg */
192*181254a7Smrg yisint = 0;
193*181254a7Smrg if (hx < 0)
194*181254a7Smrg {
195*181254a7Smrg if (iy >= 0x40700000) /* 2^113 */
196*181254a7Smrg yisint = 2; /* even integer y */
197*181254a7Smrg else if (iy >= 0x3fff0000) /* 1.0 */
198*181254a7Smrg {
199*181254a7Smrg if (floorq (y) == y)
200*181254a7Smrg {
201*181254a7Smrg z = 0.5 * y;
202*181254a7Smrg if (floorq (z) == z)
203*181254a7Smrg yisint = 2;
204*181254a7Smrg else
205*181254a7Smrg yisint = 1;
206*181254a7Smrg }
207*181254a7Smrg }
208*181254a7Smrg }
209*181254a7Smrg
210*181254a7Smrg /* special value of y */
211*181254a7Smrg if ((q.words32.w1 | q.words32.w2 | q.words32.w3) == 0)
212*181254a7Smrg {
213*181254a7Smrg if (iy == 0x7fff0000) /* y is +-inf */
214*181254a7Smrg {
215*181254a7Smrg if (((ix - 0x3fff0000) | p.words32.w1 | p.words32.w2 | p.words32.w3)
216*181254a7Smrg == 0)
217*181254a7Smrg return y - y; /* +-1**inf is NaN */
218*181254a7Smrg else if (ix >= 0x3fff0000) /* (|x|>1)**+-inf = inf,0 */
219*181254a7Smrg return (hy >= 0) ? y : zero;
220*181254a7Smrg else /* (|x|<1)**-,+inf = inf,0 */
221*181254a7Smrg return (hy < 0) ? -y : zero;
222*181254a7Smrg }
223*181254a7Smrg if (iy == 0x3fff0000)
224*181254a7Smrg { /* y is +-1 */
225*181254a7Smrg if (hy < 0)
226*181254a7Smrg return one / x;
227*181254a7Smrg else
228*181254a7Smrg return x;
229*181254a7Smrg }
230*181254a7Smrg if (hy == 0x40000000)
231*181254a7Smrg return x * x; /* y is 2 */
232*181254a7Smrg if (hy == 0x3ffe0000)
233*181254a7Smrg { /* y is 0.5 */
234*181254a7Smrg if (hx >= 0) /* x >= +0 */
235*181254a7Smrg return sqrtq (x);
236*181254a7Smrg }
237*181254a7Smrg }
238*181254a7Smrg
239*181254a7Smrg ax = fabsq (x);
240*181254a7Smrg /* special value of x */
241*181254a7Smrg if ((p.words32.w1 | p.words32.w2 | p.words32.w3) == 0)
242*181254a7Smrg {
243*181254a7Smrg if (ix == 0x7fff0000 || ix == 0 || ix == 0x3fff0000)
244*181254a7Smrg {
245*181254a7Smrg z = ax; /*x is +-0,+-inf,+-1 */
246*181254a7Smrg if (hy < 0)
247*181254a7Smrg z = one / z; /* z = (1/|x|) */
248*181254a7Smrg if (hx < 0)
249*181254a7Smrg {
250*181254a7Smrg if (((ix - 0x3fff0000) | yisint) == 0)
251*181254a7Smrg {
252*181254a7Smrg z = (z - z) / (z - z); /* (-1)**non-int is NaN */
253*181254a7Smrg }
254*181254a7Smrg else if (yisint == 1)
255*181254a7Smrg z = -z; /* (x<0)**odd = -(|x|**odd) */
256*181254a7Smrg }
257*181254a7Smrg return z;
258*181254a7Smrg }
259*181254a7Smrg }
260*181254a7Smrg
261*181254a7Smrg /* (x<0)**(non-int) is NaN */
262*181254a7Smrg if (((((uint32_t) hx >> 31) - 1) | yisint) == 0)
263*181254a7Smrg return (x - x) / (x - x);
264*181254a7Smrg
265*181254a7Smrg /* sgn (sign of result -ve**odd) = -1 else = 1 */
266*181254a7Smrg sgn = one;
267*181254a7Smrg if (((((uint32_t) hx >> 31) - 1) | (yisint - 1)) == 0)
268*181254a7Smrg sgn = -one; /* (-ve)**(odd int) */
269*181254a7Smrg
270*181254a7Smrg /* |y| is huge.
271*181254a7Smrg 2^-16495 = 1/2 of smallest representable value.
272*181254a7Smrg If (1 - 1/131072)^y underflows, y > 1.4986e9 */
273*181254a7Smrg if (iy > 0x401d654b)
274*181254a7Smrg {
275*181254a7Smrg /* if (1 - 2^-113)^y underflows, y > 1.1873e38 */
276*181254a7Smrg if (iy > 0x407d654b)
277*181254a7Smrg {
278*181254a7Smrg if (ix <= 0x3ffeffff)
279*181254a7Smrg return (hy < 0) ? huge * huge : tiny * tiny;
280*181254a7Smrg if (ix >= 0x3fff0000)
281*181254a7Smrg return (hy > 0) ? huge * huge : tiny * tiny;
282*181254a7Smrg }
283*181254a7Smrg /* over/underflow if x is not close to one */
284*181254a7Smrg if (ix < 0x3ffeffff)
285*181254a7Smrg return (hy < 0) ? sgn * huge * huge : sgn * tiny * tiny;
286*181254a7Smrg if (ix > 0x3fff0000)
287*181254a7Smrg return (hy > 0) ? sgn * huge * huge : sgn * tiny * tiny;
288*181254a7Smrg }
289*181254a7Smrg
290*181254a7Smrg ay = y > 0 ? y : -y;
291*181254a7Smrg if (ay < 0x1p-128)
292*181254a7Smrg y = y < 0 ? -0x1p-128 : 0x1p-128;
293*181254a7Smrg
294*181254a7Smrg n = 0;
295*181254a7Smrg /* take care subnormal number */
296*181254a7Smrg if (ix < 0x00010000)
297*181254a7Smrg {
298*181254a7Smrg ax *= two113;
299*181254a7Smrg n -= 113;
300*181254a7Smrg o.value = ax;
301*181254a7Smrg ix = o.words32.w0;
302*181254a7Smrg }
303*181254a7Smrg n += ((ix) >> 16) - 0x3fff;
304*181254a7Smrg j = ix & 0x0000ffff;
305*181254a7Smrg /* determine interval */
306*181254a7Smrg ix = j | 0x3fff0000; /* normalize ix */
307*181254a7Smrg if (j <= 0x3988)
308*181254a7Smrg k = 0; /* |x|<sqrt(3/2) */
309*181254a7Smrg else if (j < 0xbb67)
310*181254a7Smrg k = 1; /* |x|<sqrt(3) */
311*181254a7Smrg else
312*181254a7Smrg {
313*181254a7Smrg k = 0;
314*181254a7Smrg n += 1;
315*181254a7Smrg ix -= 0x00010000;
316*181254a7Smrg }
317*181254a7Smrg
318*181254a7Smrg o.value = ax;
319*181254a7Smrg o.words32.w0 = ix;
320*181254a7Smrg ax = o.value;
321*181254a7Smrg
322*181254a7Smrg /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
323*181254a7Smrg u = ax - bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
324*181254a7Smrg v = one / (ax + bp[k]);
325*181254a7Smrg s = u * v;
326*181254a7Smrg s_h = s;
327*181254a7Smrg
328*181254a7Smrg o.value = s_h;
329*181254a7Smrg o.words32.w3 = 0;
330*181254a7Smrg o.words32.w2 &= 0xf8000000;
331*181254a7Smrg s_h = o.value;
332*181254a7Smrg /* t_h=ax+bp[k] High */
333*181254a7Smrg t_h = ax + bp[k];
334*181254a7Smrg o.value = t_h;
335*181254a7Smrg o.words32.w3 = 0;
336*181254a7Smrg o.words32.w2 &= 0xf8000000;
337*181254a7Smrg t_h = o.value;
338*181254a7Smrg t_l = ax - (t_h - bp[k]);
339*181254a7Smrg s_l = v * ((u - s_h * t_h) - s_h * t_l);
340*181254a7Smrg /* compute log(ax) */
341*181254a7Smrg s2 = s * s;
342*181254a7Smrg u = LN[0] + s2 * (LN[1] + s2 * (LN[2] + s2 * (LN[3] + s2 * LN[4])));
343*181254a7Smrg v = LD[0] + s2 * (LD[1] + s2 * (LD[2] + s2 * (LD[3] + s2 * (LD[4] + s2))));
344*181254a7Smrg r = s2 * s2 * u / v;
345*181254a7Smrg r += s_l * (s_h + s);
346*181254a7Smrg s2 = s_h * s_h;
347*181254a7Smrg t_h = 3.0 + s2 + r;
348*181254a7Smrg o.value = t_h;
349*181254a7Smrg o.words32.w3 = 0;
350*181254a7Smrg o.words32.w2 &= 0xf8000000;
351*181254a7Smrg t_h = o.value;
352*181254a7Smrg t_l = r - ((t_h - 3.0) - s2);
353*181254a7Smrg /* u+v = s*(1+...) */
354*181254a7Smrg u = s_h * t_h;
355*181254a7Smrg v = s_l * t_h + t_l * s;
356*181254a7Smrg /* 2/(3log2)*(s+...) */
357*181254a7Smrg p_h = u + v;
358*181254a7Smrg o.value = p_h;
359*181254a7Smrg o.words32.w3 = 0;
360*181254a7Smrg o.words32.w2 &= 0xf8000000;
361*181254a7Smrg p_h = o.value;
362*181254a7Smrg p_l = v - (p_h - u);
363*181254a7Smrg z_h = cp_h * p_h; /* cp_h+cp_l = 2/(3*log2) */
364*181254a7Smrg z_l = cp_l * p_h + p_l * cp + dp_l[k];
365*181254a7Smrg /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
366*181254a7Smrg t = (__float128) n;
367*181254a7Smrg t1 = (((z_h + z_l) + dp_h[k]) + t);
368*181254a7Smrg o.value = t1;
369*181254a7Smrg o.words32.w3 = 0;
370*181254a7Smrg o.words32.w2 &= 0xf8000000;
371*181254a7Smrg t1 = o.value;
372*181254a7Smrg t2 = z_l - (((t1 - t) - dp_h[k]) - z_h);
373*181254a7Smrg
374*181254a7Smrg /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
375*181254a7Smrg y1 = y;
376*181254a7Smrg o.value = y1;
377*181254a7Smrg o.words32.w3 = 0;
378*181254a7Smrg o.words32.w2 &= 0xf8000000;
379*181254a7Smrg y1 = o.value;
380*181254a7Smrg p_l = (y - y1) * t1 + y * t2;
381*181254a7Smrg p_h = y1 * t1;
382*181254a7Smrg z = p_l + p_h;
383*181254a7Smrg o.value = z;
384*181254a7Smrg j = o.words32.w0;
385*181254a7Smrg if (j >= 0x400d0000) /* z >= 16384 */
386*181254a7Smrg {
387*181254a7Smrg /* if z > 16384 */
388*181254a7Smrg if (((j - 0x400d0000) | o.words32.w1 | o.words32.w2 | o.words32.w3) != 0)
389*181254a7Smrg return sgn * huge * huge; /* overflow */
390*181254a7Smrg else
391*181254a7Smrg {
392*181254a7Smrg if (p_l + ovt > z - p_h)
393*181254a7Smrg return sgn * huge * huge; /* overflow */
394*181254a7Smrg }
395*181254a7Smrg }
396*181254a7Smrg else if ((j & 0x7fffffff) >= 0x400d01b9) /* z <= -16495 */
397*181254a7Smrg {
398*181254a7Smrg /* z < -16495 */
399*181254a7Smrg if (((j - 0xc00d01bc) | o.words32.w1 | o.words32.w2 | o.words32.w3)
400*181254a7Smrg != 0)
401*181254a7Smrg return sgn * tiny * tiny; /* underflow */
402*181254a7Smrg else
403*181254a7Smrg {
404*181254a7Smrg if (p_l <= z - p_h)
405*181254a7Smrg return sgn * tiny * tiny; /* underflow */
406*181254a7Smrg }
407*181254a7Smrg }
408*181254a7Smrg /* compute 2**(p_h+p_l) */
409*181254a7Smrg i = j & 0x7fffffff;
410*181254a7Smrg k = (i >> 16) - 0x3fff;
411*181254a7Smrg n = 0;
412*181254a7Smrg if (i > 0x3ffe0000)
413*181254a7Smrg { /* if |z| > 0.5, set n = [z+0.5] */
414*181254a7Smrg n = floorq (z + 0.5Q);
415*181254a7Smrg t = n;
416*181254a7Smrg p_h -= t;
417*181254a7Smrg }
418*181254a7Smrg t = p_l + p_h;
419*181254a7Smrg o.value = t;
420*181254a7Smrg o.words32.w3 = 0;
421*181254a7Smrg o.words32.w2 &= 0xf8000000;
422*181254a7Smrg t = o.value;
423*181254a7Smrg u = t * lg2_h;
424*181254a7Smrg v = (p_l - (t - p_h)) * lg2 + t * lg2_l;
425*181254a7Smrg z = u + v;
426*181254a7Smrg w = v - (z - u);
427*181254a7Smrg /* exp(z) */
428*181254a7Smrg t = z * z;
429*181254a7Smrg u = PN[0] + t * (PN[1] + t * (PN[2] + t * (PN[3] + t * PN[4])));
430*181254a7Smrg v = PD[0] + t * (PD[1] + t * (PD[2] + t * (PD[3] + t)));
431*181254a7Smrg t1 = z - t * u / v;
432*181254a7Smrg r = (z * t1) / (t1 - two) - (w + z * w);
433*181254a7Smrg z = one - (r - z);
434*181254a7Smrg o.value = z;
435*181254a7Smrg j = o.words32.w0;
436*181254a7Smrg j += (n << 16);
437*181254a7Smrg if ((j >> 16) <= 0)
438*181254a7Smrg {
439*181254a7Smrg z = scalbnq (z, n); /* subnormal output */
440*181254a7Smrg __float128 force_underflow = z * z;
441*181254a7Smrg math_force_eval (force_underflow);
442*181254a7Smrg }
443*181254a7Smrg else
444*181254a7Smrg {
445*181254a7Smrg o.words32.w0 = j;
446*181254a7Smrg z = o.value;
447*181254a7Smrg }
448*181254a7Smrg return sgn * z;
449*181254a7Smrg }
450