17 * Returns e (2.71828...) raised to the x power.
19 * Range reduction is accomplished by separating the argument
20 * into an integer k and fraction f such that
25 * A polynomial is used to approximate exp(f)
26 * in the basic range [-0.5, 0.5].
32 * arithmetic domain # trials peak rms
33 * IEEE +- MAXLOG 100000 1.7e-7 2.8e-8
36 * Error amplification in the exponential function can be
37 * a serious matter. The error propagation involves
38 * exp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ),
39 * which shows that a 1 lsb error in representing X produces
40 * a relative error of X times 1 lsb in the function.
41 * While the routine gives an accurate result for arguments
42 * that are exactly represented by a double precision
43 * computer number, the result contains amplified roundoff
44 * error for large arguments not exactly represented.
49 * message condition value returned
50 * expf underflow x < MINLOGF 0.0
51 * expf overflow x > MAXLOGF MAXNUMF
56 Cephes Math Library Release 2.2: June, 1992
57 Copyright 1984, 1987, 1989 by Stephen L. Moshier
58 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
61 /* Single precision exponential function.
62 * test interval: [-0.5, +0.5]
64 * peak relative error: 7.6e-8
65 * rms relative error: 2.8e-8
68 extern float LOG2EF, MAXLOGF, MINLOGF, MAXNUMF;
70 static float C1 = 0.693359375;
71 static float C2 = -2.12194440e-4;
75 float floorf( float ), ldexpf( float, int );
77 float expf( float xx )
87 mtherr( "expf", OVERFLOW );
93 mtherr( "expf", UNDERFLOW );
97 /* Express e**x = e**g 2**n
98 * = e**g e**( n loge(2) )
99 * = e**( g + n loge(2) )
101 z = floorf( LOG2EF * x + 0.5 ); /* floor() truncates toward -infinity. */
107 /* Theoretical peak relative error in [-0.5, +0.5] is 4.2e-9. */
109 ((((( 1.9875691500E-4 * x
110 + 1.3981999507E-3) * x
111 + 8.3334519073E-3) * x
112 + 4.1665795894E-2) * x
113 + 1.6666665459E-1) * x
114 + 5.0000001201E-1) * z
118 /* multiply by power of 2 */