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 ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
20 ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
21 invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */
23 * Domain [-0.34568, 0.34568], range ~[-6.694e-10, 6.696e-10]:
24 * |6 / x * (1 + 2 * (1 / (exp(x) - 1) - 1 / x)) - q(x)| < 2**-30.04
25 * Scaled coefficients: Qn_here = 2**n * Qn_for_q (see s_expm1.c):
27 Q1 = -3.3333212137e-2, /* -0x888868.0p-28 */
28 Q2 = 1.5807170421e-3; /* 0xcf3010.0p-33 */
32 float_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
33 union {float f; uint32_t i;} u = {x};
34 uint32_t hx = u.i & 0x7fffffff;
35 int k, sign = u.i >> 31;
37 /* filter out huge and non-finite argument */
38 if (hx >= 0x4195b844) { /* if |x|>=27*ln2 */
39 if (hx > 0x7f800000) /* NaN */
43 if (hx > 0x42b17217) { /* x > log(FLT_MAX) */
49 /* argument reduction */
50 if (hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */
51 if (hx < 0x3F851592) { /* and |x| < 1.5 ln2 */
62 k = invln2*x + (sign ? -0.5f : 0.5f);
64 hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
69 } else if (hx < 0x33000000) { /* when |x|<2**-25, return x */
76 /* x is now in primary range */
79 r1 = 1.0f+hxs*(Q1+hxs*Q2);
81 e = hxs*((r1-t)/(6.0f - x*t));
82 if (k == 0) /* c is 0 */
86 /* exp(x) ~ 2^k (x_reduced - e + 1) */
88 return 0.5f*(x-e) - 0.5f;
91 return -2.0f*(e-(x+0.5f));
92 return 1.0f + 2.0f*(x-e);
94 u.i = (0x7f+k)<<23; /* 2^k */
96 if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */
104 u.i = (0x7f-k)<<23; /* 2^-k */
106 y = (x-e+(1-u.f))*twopk;
108 y = (x-(e+u.f)+1)*twopk;