xref: /freebsd/lib/msun/ld128/e_powl.c (revision 0dd5a560)
16813d08fSMatt Macy /*-
26813d08fSMatt Macy  * ====================================================
36813d08fSMatt Macy  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
46813d08fSMatt Macy  *
56813d08fSMatt Macy  * Developed at SunPro, a Sun Microsystems, Inc. business.
66813d08fSMatt Macy  * Permission to use, copy, modify, and distribute this
76813d08fSMatt Macy  * software is freely granted, provided that this notice
86813d08fSMatt Macy  * is preserved.
96813d08fSMatt Macy  * ====================================================
106813d08fSMatt Macy  */
116813d08fSMatt Macy 
126813d08fSMatt Macy /*
136813d08fSMatt Macy  * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
146813d08fSMatt Macy  *
156813d08fSMatt Macy  * Permission to use, copy, modify, and distribute this software for any
166813d08fSMatt Macy  * purpose with or without fee is hereby granted, provided that the above
176813d08fSMatt Macy  * copyright notice and this permission notice appear in all copies.
186813d08fSMatt Macy  *
196813d08fSMatt Macy  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
206813d08fSMatt Macy  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
216813d08fSMatt Macy  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
226813d08fSMatt Macy  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
236813d08fSMatt Macy  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
246813d08fSMatt Macy  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
256813d08fSMatt Macy  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
266813d08fSMatt Macy  */
276813d08fSMatt Macy 
286813d08fSMatt Macy /* powl(x,y) return x**y
296813d08fSMatt Macy  *
306813d08fSMatt Macy  *		      n
316813d08fSMatt Macy  * Method:  Let x =  2   * (1+f)
326813d08fSMatt Macy  *	1. Compute and return log2(x) in two pieces:
336813d08fSMatt Macy  *		log2(x) = w1 + w2,
346813d08fSMatt Macy  *	   where w1 has 113-53 = 60 bit trailing zeros.
3550757b14SPedro F. Giffuni  *	2. Perform y*log2(x) = n+y' by simulating multi-precision
366813d08fSMatt Macy  *	   arithmetic, where |y'|<=0.5.
376813d08fSMatt Macy  *	3. Return x**y = 2**n*exp(y'*log2)
386813d08fSMatt Macy  *
396813d08fSMatt Macy  * Special cases:
406813d08fSMatt Macy  *	1.  (anything) ** 0  is 1
416813d08fSMatt Macy  *	2.  (anything) ** 1  is itself
426813d08fSMatt Macy  *	3.  (anything) ** NAN is NAN
436813d08fSMatt Macy  *	4.  NAN ** (anything except 0) is NAN
446813d08fSMatt Macy  *	5.  +-(|x| > 1) **  +INF is +INF
456813d08fSMatt Macy  *	6.  +-(|x| > 1) **  -INF is +0
466813d08fSMatt Macy  *	7.  +-(|x| < 1) **  +INF is +0
476813d08fSMatt Macy  *	8.  +-(|x| < 1) **  -INF is +INF
486813d08fSMatt Macy  *	9.  +-1         ** +-INF is NAN
496813d08fSMatt Macy  *	10. +0 ** (+anything except 0, NAN)               is +0
506813d08fSMatt Macy  *	11. -0 ** (+anything except 0, NAN, odd integer)  is +0
516813d08fSMatt Macy  *	12. +0 ** (-anything except 0, NAN)               is +INF
526813d08fSMatt Macy  *	13. -0 ** (-anything except 0, NAN, odd integer)  is +INF
536813d08fSMatt Macy  *	14. -0 ** (odd integer) = -( +0 ** (odd integer) )
546813d08fSMatt Macy  *	15. +INF ** (+anything except 0,NAN) is +INF
556813d08fSMatt Macy  *	16. +INF ** (-anything except 0,NAN) is +0
566813d08fSMatt Macy  *	17. -INF ** (anything)  = -0 ** (-anything)
576813d08fSMatt Macy  *	18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
586813d08fSMatt Macy  *	19. (-anything except 0 and inf) ** (non-integer) is NAN
596813d08fSMatt Macy  *
606813d08fSMatt Macy  */
616813d08fSMatt Macy 
626813d08fSMatt Macy #include <float.h>
636813d08fSMatt Macy #include <math.h>
646813d08fSMatt Macy 
656813d08fSMatt Macy #include "math_private.h"
666813d08fSMatt Macy 
676813d08fSMatt Macy static const long double bp[] = {
686813d08fSMatt Macy   1.0L,
696813d08fSMatt Macy   1.5L,
706813d08fSMatt Macy };
716813d08fSMatt Macy 
726813d08fSMatt Macy /* log_2(1.5) */
736813d08fSMatt Macy static const long double dp_h[] = {
746813d08fSMatt Macy   0.0,
756813d08fSMatt Macy   5.8496250072115607565592654282227158546448E-1L
766813d08fSMatt Macy };
776813d08fSMatt Macy 
786813d08fSMatt Macy /* Low part of log_2(1.5) */
796813d08fSMatt Macy static const long double dp_l[] = {
806813d08fSMatt Macy   0.0,
816813d08fSMatt Macy   1.0579781240112554492329533686862998106046E-16L
826813d08fSMatt Macy };
836813d08fSMatt Macy 
846813d08fSMatt Macy static const long double zero = 0.0L,
856813d08fSMatt Macy   one = 1.0L,
866813d08fSMatt Macy   two = 2.0L,
876813d08fSMatt Macy   two113 = 1.0384593717069655257060992658440192E34L,
886813d08fSMatt Macy   huge = 1.0e3000L,
896813d08fSMatt Macy   tiny = 1.0e-3000L;
906813d08fSMatt Macy 
916813d08fSMatt Macy /* 3/2 log x = 3 z + z^3 + z^3 (z^2 R(z^2))
926813d08fSMatt Macy    z = (x-1)/(x+1)
936813d08fSMatt Macy    1 <= x <= 1.25
946813d08fSMatt Macy    Peak relative error 2.3e-37 */
956813d08fSMatt Macy static const long double LN[] =
966813d08fSMatt Macy {
976813d08fSMatt Macy  -3.0779177200290054398792536829702930623200E1L,
986813d08fSMatt Macy   6.5135778082209159921251824580292116201640E1L,
996813d08fSMatt Macy  -4.6312921812152436921591152809994014413540E1L,
1006813d08fSMatt Macy   1.2510208195629420304615674658258363295208E1L,
1016813d08fSMatt Macy  -9.9266909031921425609179910128531667336670E-1L
1026813d08fSMatt Macy };
1036813d08fSMatt Macy static const long double LD[] =
1046813d08fSMatt Macy {
1056813d08fSMatt Macy  -5.129862866715009066465422805058933131960E1L,
1066813d08fSMatt Macy   1.452015077564081884387441590064272782044E2L,
1076813d08fSMatt Macy  -1.524043275549860505277434040464085593165E2L,
1086813d08fSMatt Macy   7.236063513651544224319663428634139768808E1L,
1096813d08fSMatt Macy  -1.494198912340228235853027849917095580053E1L
1106813d08fSMatt Macy   /* 1.0E0 */
1116813d08fSMatt Macy };
1126813d08fSMatt Macy 
1136813d08fSMatt Macy /* exp(x) = 1 + x - x / (1 - 2 / (x - x^2 R(x^2)))
1146813d08fSMatt Macy    0 <= x <= 0.5
1156813d08fSMatt Macy    Peak relative error 5.7e-38  */
1166813d08fSMatt Macy static const long double PN[] =
1176813d08fSMatt Macy {
1186813d08fSMatt Macy   5.081801691915377692446852383385968225675E8L,
1196813d08fSMatt Macy   9.360895299872484512023336636427675327355E6L,
1206813d08fSMatt Macy   4.213701282274196030811629773097579432957E4L,
1216813d08fSMatt Macy   5.201006511142748908655720086041570288182E1L,
1226813d08fSMatt Macy   9.088368420359444263703202925095675982530E-3L,
1236813d08fSMatt Macy };
1246813d08fSMatt Macy static const long double PD[] =
1256813d08fSMatt Macy {
1266813d08fSMatt Macy   3.049081015149226615468111430031590411682E9L,
1276813d08fSMatt Macy   1.069833887183886839966085436512368982758E8L,
1286813d08fSMatt Macy   8.259257717868875207333991924545445705394E5L,
1296813d08fSMatt Macy   1.872583833284143212651746812884298360922E3L,
1306813d08fSMatt Macy   /* 1.0E0 */
1316813d08fSMatt Macy };
1326813d08fSMatt Macy 
1336813d08fSMatt Macy static const long double
1346813d08fSMatt Macy   /* ln 2 */
1356813d08fSMatt Macy   lg2 = 6.9314718055994530941723212145817656807550E-1L,
1366813d08fSMatt Macy   lg2_h = 6.9314718055994528622676398299518041312695E-1L,
1376813d08fSMatt Macy   lg2_l = 2.3190468138462996154948554638754786504121E-17L,
1386813d08fSMatt Macy   ovt = 8.0085662595372944372e-0017L,
1396813d08fSMatt Macy   /* 2/(3*log(2)) */
1406813d08fSMatt Macy   cp = 9.6179669392597560490661645400126142495110E-1L,
1416813d08fSMatt Macy   cp_h = 9.6179669392597555432899980587535537779331E-1L,
1426813d08fSMatt Macy   cp_l = 5.0577616648125906047157785230014751039424E-17L;
1436813d08fSMatt Macy 
1446813d08fSMatt Macy long double
powl(long double x,long double y)1456813d08fSMatt Macy powl(long double x, long double y)
1466813d08fSMatt Macy {
1476813d08fSMatt Macy   long double z, ax, z_h, z_l, p_h, p_l;
1486813d08fSMatt Macy   long double yy1, t1, t2, r, s, t, u, v, w;
1496813d08fSMatt Macy   long double s2, s_h, s_l, t_h, t_l;
1506813d08fSMatt Macy   int32_t i, j, k, yisint, n;
1516813d08fSMatt Macy   u_int32_t ix, iy;
1526813d08fSMatt Macy   int32_t hx, hy;
1536813d08fSMatt Macy   ieee_quad_shape_type o, p, q;
1546813d08fSMatt Macy 
1556813d08fSMatt Macy   p.value = x;
1566813d08fSMatt Macy   hx = p.parts32.mswhi;
1576813d08fSMatt Macy   ix = hx & 0x7fffffff;
1586813d08fSMatt Macy 
1596813d08fSMatt Macy   q.value = y;
1606813d08fSMatt Macy   hy = q.parts32.mswhi;
1616813d08fSMatt Macy   iy = hy & 0x7fffffff;
1626813d08fSMatt Macy 
1636813d08fSMatt Macy 
1646813d08fSMatt Macy   /* y==zero: x**0 = 1 */
1656813d08fSMatt Macy   if ((iy | q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) == 0)
1666813d08fSMatt Macy     return one;
1676813d08fSMatt Macy 
1686813d08fSMatt Macy   /* 1.0**y = 1; -1.0**+-Inf = 1 */
1696813d08fSMatt Macy   if (x == one)
1706813d08fSMatt Macy     return one;
1716813d08fSMatt Macy   if (x == -1.0L && iy == 0x7fff0000
1726813d08fSMatt Macy       && (q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) == 0)
1736813d08fSMatt Macy     return one;
1746813d08fSMatt Macy 
1756813d08fSMatt Macy   /* +-NaN return x+y */
1766813d08fSMatt Macy   if ((ix > 0x7fff0000)
1776813d08fSMatt Macy       || ((ix == 0x7fff0000)
1786813d08fSMatt Macy 	  && ((p.parts32.mswlo | p.parts32.lswhi | p.parts32.lswlo) != 0))
1796813d08fSMatt Macy       || (iy > 0x7fff0000)
1806813d08fSMatt Macy       || ((iy == 0x7fff0000)
1816813d08fSMatt Macy 	  && ((q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) != 0)))
1826f1b8a07SBruce Evans     return nan_mix(x, y);
1836813d08fSMatt Macy 
1846813d08fSMatt Macy   /* determine if y is an odd int when x < 0
1856813d08fSMatt Macy    * yisint = 0       ... y is not an integer
1866813d08fSMatt Macy    * yisint = 1       ... y is an odd int
1876813d08fSMatt Macy    * yisint = 2       ... y is an even int
1886813d08fSMatt Macy    */
1896813d08fSMatt Macy   yisint = 0;
1906813d08fSMatt Macy   if (hx < 0)
1916813d08fSMatt Macy     {
1926813d08fSMatt Macy       if (iy >= 0x40700000)	/* 2^113 */
1936813d08fSMatt Macy 	yisint = 2;		/* even integer y */
1946813d08fSMatt Macy       else if (iy >= 0x3fff0000)	/* 1.0 */
1956813d08fSMatt Macy 	{
1966813d08fSMatt Macy 	  if (floorl (y) == y)
1976813d08fSMatt Macy 	    {
1986813d08fSMatt Macy 	      z = 0.5 * y;
1996813d08fSMatt Macy 	      if (floorl (z) == z)
2006813d08fSMatt Macy 		yisint = 2;
2016813d08fSMatt Macy 	      else
2026813d08fSMatt Macy 		yisint = 1;
2036813d08fSMatt Macy 	    }
2046813d08fSMatt Macy 	}
2056813d08fSMatt Macy     }
2066813d08fSMatt Macy 
2076813d08fSMatt Macy   /* special value of y */
2086813d08fSMatt Macy   if ((q.parts32.mswlo | q.parts32.lswhi | q.parts32.lswlo) == 0)
2096813d08fSMatt Macy     {
2106813d08fSMatt Macy       if (iy == 0x7fff0000)	/* y is +-inf */
2116813d08fSMatt Macy 	{
2126813d08fSMatt Macy 	  if (((ix - 0x3fff0000) | p.parts32.mswlo | p.parts32.lswhi |
2136813d08fSMatt Macy 	    p.parts32.lswlo) == 0)
2146813d08fSMatt Macy 	    return y - y;	/* +-1**inf is NaN */
2156813d08fSMatt Macy 	  else if (ix >= 0x3fff0000)	/* (|x|>1)**+-inf = inf,0 */
2166813d08fSMatt Macy 	    return (hy >= 0) ? y : zero;
2176813d08fSMatt Macy 	  else			/* (|x|<1)**-,+inf = inf,0 */
2186813d08fSMatt Macy 	    return (hy < 0) ? -y : zero;
2196813d08fSMatt Macy 	}
2206813d08fSMatt Macy       if (iy == 0x3fff0000)
2216813d08fSMatt Macy 	{			/* y is  +-1 */
2226813d08fSMatt Macy 	  if (hy < 0)
2236813d08fSMatt Macy 	    return one / x;
2246813d08fSMatt Macy 	  else
2256813d08fSMatt Macy 	    return x;
2266813d08fSMatt Macy 	}
2276813d08fSMatt Macy       if (hy == 0x40000000)
2286813d08fSMatt Macy 	return x * x;		/* y is  2 */
2296813d08fSMatt Macy       if (hy == 0x3ffe0000)
2306813d08fSMatt Macy 	{			/* y is  0.5 */
2316813d08fSMatt Macy 	  if (hx >= 0)		/* x >= +0 */
2326813d08fSMatt Macy 	    return sqrtl (x);
2336813d08fSMatt Macy 	}
2346813d08fSMatt Macy     }
2356813d08fSMatt Macy 
2366813d08fSMatt Macy   ax = fabsl (x);
2376813d08fSMatt Macy   /* special value of x */
2386813d08fSMatt Macy   if ((p.parts32.mswlo | p.parts32.lswhi | p.parts32.lswlo) == 0)
2396813d08fSMatt Macy     {
2406813d08fSMatt Macy       if (ix == 0x7fff0000 || ix == 0 || ix == 0x3fff0000)
2416813d08fSMatt Macy 	{
2426813d08fSMatt Macy 	  z = ax;		/*x is +-0,+-inf,+-1 */
2436813d08fSMatt Macy 	  if (hy < 0)
2446813d08fSMatt Macy 	    z = one / z;	/* z = (1/|x|) */
2456813d08fSMatt Macy 	  if (hx < 0)
2466813d08fSMatt Macy 	    {
2476813d08fSMatt Macy 	      if (((ix - 0x3fff0000) | yisint) == 0)
2486813d08fSMatt Macy 		{
2496813d08fSMatt Macy 		  z = (z - z) / (z - z);	/* (-1)**non-int is NaN */
2506813d08fSMatt Macy 		}
2516813d08fSMatt Macy 	      else if (yisint == 1)
2526813d08fSMatt Macy 		z = -z;		/* (x<0)**odd = -(|x|**odd) */
2536813d08fSMatt Macy 	    }
2546813d08fSMatt Macy 	  return z;
2556813d08fSMatt Macy 	}
2566813d08fSMatt Macy     }
2576813d08fSMatt Macy 
2586813d08fSMatt Macy   /* (x<0)**(non-int) is NaN */
2596813d08fSMatt Macy   if (((((u_int32_t) hx >> 31) - 1) | yisint) == 0)
2606813d08fSMatt Macy     return (x - x) / (x - x);
2616813d08fSMatt Macy 
2626813d08fSMatt Macy   /* |y| is huge.
2636813d08fSMatt Macy      2^-16495 = 1/2 of smallest representable value.
2646813d08fSMatt Macy      If (1 - 1/131072)^y underflows, y > 1.4986e9 */
2656813d08fSMatt Macy   if (iy > 0x401d654b)
2666813d08fSMatt Macy     {
2676813d08fSMatt Macy       /* if (1 - 2^-113)^y underflows, y > 1.1873e38 */
2686813d08fSMatt Macy       if (iy > 0x407d654b)
2696813d08fSMatt Macy 	{
2706813d08fSMatt Macy 	  if (ix <= 0x3ffeffff)
2716813d08fSMatt Macy 	    return (hy < 0) ? huge * huge : tiny * tiny;
2726813d08fSMatt Macy 	  if (ix >= 0x3fff0000)
2736813d08fSMatt Macy 	    return (hy > 0) ? huge * huge : tiny * tiny;
2746813d08fSMatt Macy 	}
2756813d08fSMatt Macy       /* over/underflow if x is not close to one */
2766813d08fSMatt Macy       if (ix < 0x3ffeffff)
2776813d08fSMatt Macy 	return (hy < 0) ? huge * huge : tiny * tiny;
2786813d08fSMatt Macy       if (ix > 0x3fff0000)
2796813d08fSMatt Macy 	return (hy > 0) ? huge * huge : tiny * tiny;
2806813d08fSMatt Macy     }
2816813d08fSMatt Macy 
2826813d08fSMatt Macy   n = 0;
2836813d08fSMatt Macy   /* take care subnormal number */
2846813d08fSMatt Macy   if (ix < 0x00010000)
2856813d08fSMatt Macy     {
2866813d08fSMatt Macy       ax *= two113;
2876813d08fSMatt Macy       n -= 113;
2886813d08fSMatt Macy       o.value = ax;
2896813d08fSMatt Macy       ix = o.parts32.mswhi;
2906813d08fSMatt Macy     }
2916813d08fSMatt Macy   n += ((ix) >> 16) - 0x3fff;
2926813d08fSMatt Macy   j = ix & 0x0000ffff;
2936813d08fSMatt Macy   /* determine interval */
2946813d08fSMatt Macy   ix = j | 0x3fff0000;		/* normalize ix */
2956813d08fSMatt Macy   if (j <= 0x3988)
2966813d08fSMatt Macy     k = 0;			/* |x|<sqrt(3/2) */
2976813d08fSMatt Macy   else if (j < 0xbb67)
2986813d08fSMatt Macy     k = 1;			/* |x|<sqrt(3)   */
2996813d08fSMatt Macy   else
3006813d08fSMatt Macy     {
3016813d08fSMatt Macy       k = 0;
3026813d08fSMatt Macy       n += 1;
3036813d08fSMatt Macy       ix -= 0x00010000;
3046813d08fSMatt Macy     }
3056813d08fSMatt Macy 
3066813d08fSMatt Macy   o.value = ax;
3076813d08fSMatt Macy   o.parts32.mswhi = ix;
3086813d08fSMatt Macy   ax = o.value;
3096813d08fSMatt Macy 
3106813d08fSMatt Macy   /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
3116813d08fSMatt Macy   u = ax - bp[k];		/* bp[0]=1.0, bp[1]=1.5 */
3126813d08fSMatt Macy   v = one / (ax + bp[k]);
3136813d08fSMatt Macy   s = u * v;
3146813d08fSMatt Macy   s_h = s;
3156813d08fSMatt Macy 
3166813d08fSMatt Macy   o.value = s_h;
3176813d08fSMatt Macy   o.parts32.lswlo = 0;
3186813d08fSMatt Macy   o.parts32.lswhi &= 0xf8000000;
3196813d08fSMatt Macy   s_h = o.value;
3206813d08fSMatt Macy   /* t_h=ax+bp[k] High */
3216813d08fSMatt Macy   t_h = ax + bp[k];
3226813d08fSMatt Macy   o.value = t_h;
3236813d08fSMatt Macy   o.parts32.lswlo = 0;
3246813d08fSMatt Macy   o.parts32.lswhi &= 0xf8000000;
3256813d08fSMatt Macy   t_h = o.value;
3266813d08fSMatt Macy   t_l = ax - (t_h - bp[k]);
3276813d08fSMatt Macy   s_l = v * ((u - s_h * t_h) - s_h * t_l);
3286813d08fSMatt Macy   /* compute log(ax) */
3296813d08fSMatt Macy   s2 = s * s;
3306813d08fSMatt Macy   u = LN[0] + s2 * (LN[1] + s2 * (LN[2] + s2 * (LN[3] + s2 * LN[4])));
3316813d08fSMatt Macy   v = LD[0] + s2 * (LD[1] + s2 * (LD[2] + s2 * (LD[3] + s2 * (LD[4] + s2))));
3326813d08fSMatt Macy   r = s2 * s2 * u / v;
3336813d08fSMatt Macy   r += s_l * (s_h + s);
3346813d08fSMatt Macy   s2 = s_h * s_h;
3356813d08fSMatt Macy   t_h = 3.0 + s2 + r;
3366813d08fSMatt Macy   o.value = t_h;
3376813d08fSMatt Macy   o.parts32.lswlo = 0;
3386813d08fSMatt Macy   o.parts32.lswhi &= 0xf8000000;
3396813d08fSMatt Macy   t_h = o.value;
3406813d08fSMatt Macy   t_l = r - ((t_h - 3.0) - s2);
3416813d08fSMatt Macy   /* u+v = s*(1+...) */
3426813d08fSMatt Macy   u = s_h * t_h;
3436813d08fSMatt Macy   v = s_l * t_h + t_l * s;
3446813d08fSMatt Macy   /* 2/(3log2)*(s+...) */
3456813d08fSMatt Macy   p_h = u + v;
3466813d08fSMatt Macy   o.value = p_h;
3476813d08fSMatt Macy   o.parts32.lswlo = 0;
3486813d08fSMatt Macy   o.parts32.lswhi &= 0xf8000000;
3496813d08fSMatt Macy   p_h = o.value;
3506813d08fSMatt Macy   p_l = v - (p_h - u);
3516813d08fSMatt Macy   z_h = cp_h * p_h;		/* cp_h+cp_l = 2/(3*log2) */
3526813d08fSMatt Macy   z_l = cp_l * p_h + p_l * cp + dp_l[k];
3536813d08fSMatt Macy   /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
3546813d08fSMatt Macy   t = (long double) n;
3556813d08fSMatt Macy   t1 = (((z_h + z_l) + dp_h[k]) + t);
3566813d08fSMatt Macy   o.value = t1;
3576813d08fSMatt Macy   o.parts32.lswlo = 0;
3586813d08fSMatt Macy   o.parts32.lswhi &= 0xf8000000;
3596813d08fSMatt Macy   t1 = o.value;
3606813d08fSMatt Macy   t2 = z_l - (((t1 - t) - dp_h[k]) - z_h);
3616813d08fSMatt Macy 
3626813d08fSMatt Macy   /* s (sign of result -ve**odd) = -1 else = 1 */
3636813d08fSMatt Macy   s = one;
3646813d08fSMatt Macy   if (((((u_int32_t) hx >> 31) - 1) | (yisint - 1)) == 0)
3656813d08fSMatt Macy     s = -one;			/* (-ve)**(odd int) */
3666813d08fSMatt Macy 
3676813d08fSMatt Macy   /* split up y into yy1+y2 and compute (yy1+y2)*(t1+t2) */
3686813d08fSMatt Macy   yy1 = y;
3696813d08fSMatt Macy   o.value = yy1;
3706813d08fSMatt Macy   o.parts32.lswlo = 0;
3716813d08fSMatt Macy   o.parts32.lswhi &= 0xf8000000;
3726813d08fSMatt Macy   yy1 = o.value;
3736813d08fSMatt Macy   p_l = (y - yy1) * t1 + y * t2;
3746813d08fSMatt Macy   p_h = yy1 * t1;
3756813d08fSMatt Macy   z = p_l + p_h;
3766813d08fSMatt Macy   o.value = z;
3776813d08fSMatt Macy   j = o.parts32.mswhi;
3786813d08fSMatt Macy   if (j >= 0x400d0000) /* z >= 16384 */
3796813d08fSMatt Macy     {
3806813d08fSMatt Macy       /* if z > 16384 */
3816813d08fSMatt Macy       if (((j - 0x400d0000) | o.parts32.mswlo | o.parts32.lswhi |
3826813d08fSMatt Macy 	o.parts32.lswlo) != 0)
3836813d08fSMatt Macy 	return s * huge * huge;	/* overflow */
3846813d08fSMatt Macy       else
3856813d08fSMatt Macy 	{
3866813d08fSMatt Macy 	  if (p_l + ovt > z - p_h)
3876813d08fSMatt Macy 	    return s * huge * huge;	/* overflow */
3886813d08fSMatt Macy 	}
3896813d08fSMatt Macy     }
3906813d08fSMatt Macy   else if ((j & 0x7fffffff) >= 0x400d01b9)	/* z <= -16495 */
3916813d08fSMatt Macy     {
3926813d08fSMatt Macy       /* z < -16495 */
3936813d08fSMatt Macy       if (((j - 0xc00d01bc) | o.parts32.mswlo | o.parts32.lswhi |
3946813d08fSMatt Macy 	o.parts32.lswlo)
3956813d08fSMatt Macy 	  != 0)
3966813d08fSMatt Macy 	return s * tiny * tiny;	/* underflow */
3976813d08fSMatt Macy       else
3986813d08fSMatt Macy 	{
3996813d08fSMatt Macy 	  if (p_l <= z - p_h)
4006813d08fSMatt Macy 	    return s * tiny * tiny;	/* underflow */
4016813d08fSMatt Macy 	}
4026813d08fSMatt Macy     }
4036813d08fSMatt Macy   /* compute 2**(p_h+p_l) */
4046813d08fSMatt Macy   i = j & 0x7fffffff;
4056813d08fSMatt Macy   k = (i >> 16) - 0x3fff;
4066813d08fSMatt Macy   n = 0;
4076813d08fSMatt Macy   if (i > 0x3ffe0000)
4086813d08fSMatt Macy     {				/* if |z| > 0.5, set n = [z+0.5] */
4096813d08fSMatt Macy       n = floorl (z + 0.5L);
4106813d08fSMatt Macy       t = n;
4116813d08fSMatt Macy       p_h -= t;
4126813d08fSMatt Macy     }
4136813d08fSMatt Macy   t = p_l + p_h;
4146813d08fSMatt Macy   o.value = t;
4156813d08fSMatt Macy   o.parts32.lswlo = 0;
4166813d08fSMatt Macy   o.parts32.lswhi &= 0xf8000000;
4176813d08fSMatt Macy   t = o.value;
4186813d08fSMatt Macy   u = t * lg2_h;
4196813d08fSMatt Macy   v = (p_l - (t - p_h)) * lg2 + t * lg2_l;
4206813d08fSMatt Macy   z = u + v;
4216813d08fSMatt Macy   w = v - (z - u);
4226813d08fSMatt Macy   /*  exp(z) */
4236813d08fSMatt Macy   t = z * z;
4246813d08fSMatt Macy   u = PN[0] + t * (PN[1] + t * (PN[2] + t * (PN[3] + t * PN[4])));
4256813d08fSMatt Macy   v = PD[0] + t * (PD[1] + t * (PD[2] + t * (PD[3] + t)));
4266813d08fSMatt Macy   t1 = z - t * u / v;
4276813d08fSMatt Macy   r = (z * t1) / (t1 - two) - (w + z * w);
4286813d08fSMatt Macy   z = one - (r - z);
4296813d08fSMatt Macy   o.value = z;
4306813d08fSMatt Macy   j = o.parts32.mswhi;
4316813d08fSMatt Macy   j += (n << 16);
4326813d08fSMatt Macy   if ((j >> 16) <= 0)
4336813d08fSMatt Macy     z = scalbnl (z, n);	/* subnormal output */
4346813d08fSMatt Macy   else
4356813d08fSMatt Macy     {
4366813d08fSMatt Macy       o.parts32.mswhi = j;
4376813d08fSMatt Macy       z = o.value;
4386813d08fSMatt Macy     }
4396813d08fSMatt Macy   return s * z;
4406813d08fSMatt Macy }
441