s_expm1.c (59b19ff14a36bb975819fff8c7bd8648a9b29537) s_expm1.c (a00672cff92a23dd28a5e6a1f3a52189eb0d7d7a)
1/* @(#)s_expm1.c 5.1 93/09/24 */
2/*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 *
6 * Developed at SunPro, 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
1/* @(#)s_expm1.c 5.1 93/09/24 */
2/*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 *
6 * Developed at SunPro, 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
13#ifndef lint
14static char rcsid[] = "$FreeBSD$";
15#endif
13#include <sys/cdefs.h>
14__FBSDID("$FreeBSD$");
16
17/* expm1(x)
18 * Returns exp(x)-1, the exponential of x minus 1.
19 *
20 * Method
21 * 1. Argument reduction:
22 * Given x, find r and integer k such that
23 *

--- 101 unchanged lines hidden (view full) ---

125Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */
126Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */
127Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */
128Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
129
130double
131expm1(double x)
132{
15
16/* expm1(x)
17 * Returns exp(x)-1, the exponential of x minus 1.
18 *
19 * Method
20 * 1. Argument reduction:
21 * Given x, find r and integer k such that
22 *

--- 101 unchanged lines hidden (view full) ---

124Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */
125Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */
126Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */
127Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
128
129double
130expm1(double x)
131{
133 double y,hi,lo,c,t,e,hxs,hfx,r1;
132 double y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
134 int32_t k,xsb;
135 u_int32_t hx;
136
137 GET_HIGH_WORD(hx,x);
138 xsb = hx&0x80000000; /* sign bit of x */
139 if(xsb==0) y=x; else y= -x; /* y = |x| */
140 hx &= 0x7fffffff; /* high word of |x| */
141

--- 40 unchanged lines hidden (view full) ---

182 /* x is now in primary range */
183 hfx = 0.5*x;
184 hxs = x*hfx;
185 r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
186 t = 3.0-r1*hfx;
187 e = hxs*((r1-t)/(6.0 - x*t));
188 if(k==0) return x - (x*e-hxs); /* c is 0 */
189 else {
133 int32_t k,xsb;
134 u_int32_t hx;
135
136 GET_HIGH_WORD(hx,x);
137 xsb = hx&0x80000000; /* sign bit of x */
138 if(xsb==0) y=x; else y= -x; /* y = |x| */
139 hx &= 0x7fffffff; /* high word of |x| */
140

--- 40 unchanged lines hidden (view full) ---

181 /* x is now in primary range */
182 hfx = 0.5*x;
183 hxs = x*hfx;
184 r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
185 t = 3.0-r1*hfx;
186 e = hxs*((r1-t)/(6.0 - x*t));
187 if(k==0) return x - (x*e-hxs); /* c is 0 */
188 else {
189 INSERT_WORDS(twopk,0x3ff00000+(k<<20),0); /* 2^k */
190 e = (x*(e-c)-c);
191 e -= hxs;
192 if(k== -1) return 0.5*(x-e)-0.5;
193 if(k==1)
194 if(x < -0.25) return -2.0*(e-(x+0.5));
195 else return one+2.0*(x-e);
196 if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
190 e = (x*(e-c)-c);
191 e -= hxs;
192 if(k== -1) return 0.5*(x-e)-0.5;
193 if(k==1)
194 if(x < -0.25) return -2.0*(e-(x+0.5));
195 else return one+2.0*(x-e);
196 if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
197 u_int32_t high;
198 y = one-(e-x);
197 y = one-(e-x);
199 GET_HIGH_WORD(high,y);
200 SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
198 if (k == 1024) y = y*2.0*0x1p1023;
199 else y = y*twopk;
201 return y-one;
202 }
203 t = one;
204 if(k<20) {
200 return y-one;
201 }
202 t = one;
203 if(k<20) {
205 u_int32_t high;
206 SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */
207 y = t-(e-x);
204 SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */
205 y = t-(e-x);
208 GET_HIGH_WORD(high,y);
209 SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
206 y = y*twopk;
210 } else {
207 } else {
211 u_int32_t high;
212 SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */
213 y = x-(e+t);
214 y += one;
208 SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */
209 y = x-(e+t);
210 y += one;
215 GET_HIGH_WORD(high,y);
216 SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
211 y = y*twopk;
217 }
218 }
219 return y;
220}
212 }
213 }
214 return y;
215}