1: 2: 3:
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: #include "math.h"
17: #include "math_private.h"
18:
19: static const volatile float huge = 1.0e+30;
20:
21: static const float
22: one = 1.0,
23: halF[2] = {0.5,-0.5,},
24: twom100 = 7.8886090522e-31,
25: o_threshold= 8.8721679688e+01,
26: u_threshold= -1.0397208405e+02,
27: ln2HI[2] ={ 6.9313812256e-01,
28: -6.9313812256e-01,},
29: ln2LO[2] ={ 9.0580006145e-06,
30: -9.0580006145e-06,},
31: invln2 = 1.4426950216e+00,
32: P1 = 1.6666667163e-01,
33: P2 = -2.7777778450e-03,
34: P3 = 6.6137559770e-05,
35: P4 = -1.6533901999e-06,
36: P5 = 4.1381369442e-08;
37:
38: float
39: expf(float x)
40: {
41: float y,hi,lo,c,t;
42: int32_t k,xsb;
43: u_int32_t hx;
44:
45: GET_FLOAT_WORD(hx,x);
46: xsb = (hx>>31)&1;
47: hx &= 0x7fffffff;
48:
49:
50: if(hx >= 0x42b17218) {
51: if(hx>0x7f800000)
52: return x+x;
53: if(hx==0x7f800000)
54: return (xsb==0)? x:0.0;
55: if(x > o_threshold) return huge*huge;
56: if(x < u_threshold) return twom100*twom100;
57: }
58:
59:
60: if(hx > 0x3eb17218) {
61: if(hx < 0x3F851592) {
62: hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
63: } else {
64: k = invln2*x+halF[xsb];
65: t = k;
66: hi = x - t*ln2HI[0];
67: lo = t*ln2LO[0];
68: }
69: x = hi - lo;
70: }
71: else if(hx < 0x31800000) {
72: if(huge+x>one) return one+x;
73: }
74: else k = 0;
75:
76:
77: t = x*x;
78: c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
79: if(k==0) return one-((x*c)/(c-(float)2.0)-x);
80: else y = one-((lo-(x*c)/((float)2.0-c))-hi);
81: if(k >= -125) {
82: u_int32_t hy;
83: GET_FLOAT_WORD(hy,y);
84: SET_FLOAT_WORD(y,hy+(k<<23));
85: return y;
86: } else {
87: u_int32_t hy;
88: GET_FLOAT_WORD(hy,y);
89: SET_FLOAT_WORD(y,hy+((k+100)<<23));
90: return y*twom100;
91: }
92: }