2 /* @(#)z_expf.c 1.0 98/08/13 */
3 /******************************************************************
4 * The following routines are coded directly from the algorithms
5 * and coefficients given in "Software Manual for the Elementary
6 * Functions" by William J. Cody, Jr. and William Waite, Prentice
8 ******************************************************************/
9 /******************************************************************
10 * Exponential Function
13 * x - floating point value
19 * This routine returns e raised to the xth power.
21 *****************************************************************/
27 static const float INV_LN2
= 1.442695040;
28 static const float LN2
= 0.693147180;
29 static const float p
[] = { 0.249999999950, 0.00416028863 };
30 static const float q
[] = { 0.5, 0.04998717878 };
46 return (z_infinity_f
.f
);
53 /* Check for out of bounds. */
54 if (x
> BIGX
|| x
< SMALLX
)
60 /* Check for a value too small to calculate. */
61 if (-z_rooteps_f
< x
&& x
< z_rooteps_f
)
66 /* Calculate the exponent. */
68 N
= (int) (x
* INV_LN2
- 0.5);
70 N
= (int) (x
* INV_LN2
+ 0.5);
72 /* Construct the mantissa. */
75 P
= g
* (p
[1] * z
+ p
[0]);
77 R
= 0.5 + P
/ (Q
- P
);
79 /* Return the floating point value. */
81 return (ldexpf (R
, N
));
84 #ifdef _DOUBLE_IS_32BITS
88 return (double) expf ((float) x
);
91 #endif /* _DOUBLE_IS_32BITS */