3 * Base 2 exponential function
17 * Returns 2 raised to the x power.
19 * Range reduction is accomplished by separating the argument
20 * into an integer k and fraction f such that
26 * 1 + 2x P(x**2) / (Q(x**2) - x P(x**2) )
28 * approximates 2**x in the basic range [-0.5, 0.5].
34 * arithmetic domain # trials peak rms
35 * IEEE -1022,+1024 30000 1.8e-16 5.4e-17
38 * See exp.c for comments on error amplification.
43 * message condition value returned
44 * exp underflow x < -MAXL2 0.0
45 * exp overflow x > MAXL2 MAXNUM
47 * For DEC arithmetic, MAXL2 = 127.
48 * For IEEE arithmetic, MAXL2 = 1024.
53 Cephes Math Library Release 2.8: June, 2000
54 Copyright 1984, 1995, 2000 by Stephen L. Moshier
63 2.30933477057345225087E-2,
64 2.02020656693165307700E1,
65 1.51390680115615096133E3,
68 /* 1.00000000000000000000E0,*/
69 2.33184211722314911771E2,
70 4.36821166879210612817E3,
77 static unsigned short P[] = {
78 0036675,0027102,0122327,0053227,
79 0041241,0116724,0115412,0157355,
80 0042675,0036404,0101733,0132226,
82 static unsigned short Q[] = {
83 /*0040200,0000000,0000000,0000000,*/
84 0042151,0027450,0077732,0160744,
85 0043210,0100661,0077550,0056560,
92 static unsigned short P[] = {
93 0xead3,0x549a,0xa5c8,0x3f97,
94 0x5bde,0x9361,0x33ba,0x4034,
95 0x7693,0x907b,0xa7a0,0x4097,
97 static unsigned short Q[] = {
98 /*0x0000,0x0000,0x0000,0x3ff0,*/
99 0x5c3c,0x0ffb,0x25e5,0x406d,
100 0x0bae,0x2fed,0x1036,0x40b1,
103 #define MINL2 -1022.0
107 static unsigned short P[] = {
108 0x3f97,0xa5c8,0x549a,0xead3,
109 0x4034,0x33ba,0x9361,0x5bde,
110 0x4097,0xa7a0,0x907b,0x7693,
112 static unsigned short Q[] = {
113 /*0x3ff0,0x0000,0x0000,0x0000,*/
114 0x406d,0x25e5,0x0ffb,0x5c3c,
115 0x40b1,0x1036,0x2fed,0x0bae,
118 #define MINL2 -1022.0
122 extern double polevl ( double, void *, int );
123 extern double p1evl ( double, void *, int );
124 extern double floor ( double );
125 extern double ldexp ( double, int );
126 extern int isnan ( double );
127 extern int isfinite ( double );
129 double polevl(), p1evl(), floor(), ldexp();
130 int isnan(), isfinite();
133 extern double INFINITY;
135 extern double MAXNUM;
152 mtherr( "exp2", OVERFLOW );
160 mtherr( "exp2", UNDERFLOW );
166 /* separate into integer and fractional parts */
171 /* rational approximation
172 * exp2(x) = 1 + 2xP(xx)/(Q(xx) - P(xx))
176 px = x * polevl( xx, P, 2 );
177 x = px / ( p1evl( xx, Q, 2 ) - px );
178 x = 1.0 + ldexp( x, 1 );
180 /* scale by power of 2 */