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 * ====================================================
19 o_threshold = 8.8721679688e+01, /* 0x42b17180 */
20 ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
21 ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
22 invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */
24 * Domain [-0.34568, 0.34568], range ~[-6.694e-10, 6.696e-10]:
25 * |6 / x * (1 + 2 * (1 / (exp(x) - 1) - 1 / x)) - q(x)| < 2**-30.04
26 * Scaled coefficients: Qn_here = 2**n * Qn_for_q (see s_expm1.c):
28 Q1 = -3.3333212137e-2, /* -0x888868.0p-28 */
29 Q2 = 1.5807170421e-3; /* 0xcf3010.0p-33 */
33 float_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
34 union {float f; uint32_t i;} u = {x};
35 uint32_t hx = u.i & 0x7fffffff;
36 int k, sign = u.i >> 31;
38 /* filter out huge and non-finite argument */
39 if (hx >= 0x4195b844) { /* if |x|>=27*ln2 */
40 if (hx > 0x7f800000) /* NaN */
44 if (x > o_threshold) {
50 /* argument reduction */
51 if (hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */
52 if (hx < 0x3F851592) { /* and |x| < 1.5 ln2 */
63 k = invln2*x + (sign ? -0.5f : 0.5f);
65 hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
70 } else if (hx < 0x33000000) { /* when |x|<2**-25, return x */
77 /* x is now in primary range */
80 r1 = 1.0f+hxs*(Q1+hxs*Q2);
82 e = hxs*((r1-t)/(6.0f - x*t));
83 if (k == 0) /* c is 0 */
87 /* exp(x) ~ 2^k (x_reduced - e + 1) */
89 return 0.5f*(x-e) - 0.5f;
92 return -2.0f*(e-(x+0.5f));
93 return 1.0f + 2.0f*(x-e);
95 u.i = (0x7f+k)<<23; /* 2^k */
97 if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */
105 u.i = (0x7f-k)<<23; /* 2^-k */
107 y = (x-e+(1-u.f))*twopk;
109 y = (x-(e+u.f)+1)*twopk;