1 /* origin: FreeBSD /usr/src/lib/msun/src/s_expm1f.c */
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
22 o_threshold = 8.8721679688e+01, /* 0x42b17180 */
23 ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
24 ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
25 invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */
27 * Domain [-0.34568, 0.34568], range ~[-6.694e-10, 6.696e-10]:
28 * |6 / x * (1 + 2 * (1 / (exp(x) - 1) - 1 / x)) - q(x)| < 2**-30.04
29 * Scaled coefficients: Qn_here = 2**n * Qn_for_q (see s_expm1.c):
31 Q1 = -3.3333212137e-2, /* -0x888868.0p-28 */
32 Q2 = 1.5807170421e-3; /* 0xcf3010.0p-33 */
36 float y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
40 GET_FLOAT_WORD(hx, x);
41 xsb = hx&0x80000000; /* sign bit of x */
42 hx &= 0x7fffffff; /* high word of |x| */
44 /* filter out huge and non-finite argument */
45 if (hx >= 0x4195b844) { /* if |x|>=27*ln2 */
46 if (hx >= 0x42b17218) { /* if |x|>=88.721... */
47 if (hx > 0x7f800000) /* NaN */
49 if (hx == 0x7f800000) /* exp(+-inf)={inf,-1} */
50 return xsb==0 ? x : -1.0;
52 return huge*huge; /* overflow */
54 if (xsb != 0) { /* x < -27*ln2 */
57 return tiny-one; /* return -1 */
61 /* argument reduction */
62 if (hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */
63 if (hx < 0x3F851592) { /* and |x| < 1.5 ln2 */
74 k = invln2*x + (xsb==0 ? 0.5f : -0.5f);
76 hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
79 STRICT_ASSIGN(float, x, hi - lo);
81 } else if (hx < 0x33000000) { /* when |x|<2**-25, return x */
82 t = huge+x; /* return x with inexact flags when x!=0 */
83 return x - (t-(huge+x));
87 /* x is now in primary range */
90 r1 = one+hxs*(Q1+hxs*Q2);
92 e = hxs*((r1-t)/(6.0f - x*t));
93 if (k == 0) /* c is 0 */
95 SET_FLOAT_WORD(twopk, 0x3f800000+(k<<23)); /* 2^k */
99 return 0.5f*(x-e) - 0.5f;
102 return -2.0f*(e-(x+0.5f));
103 return one + 2.0f*(x-e);
105 if (k <= -2 || k > 56) { /* suffice to return exp(x)-1 */
115 SET_FLOAT_WORD(t, 0x3f800000 - (0x1000000>>k)); /* t=1-2^-k */
119 SET_FLOAT_WORD(t, (0x7f-k)<<23); /* 2^-k */