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 };
33 _DEFUN (expf
, (float),
47 return (z_infinity_f
.f
);
54 /* Check for out of bounds. */
55 if (x
> BIGX
|| x
< SMALLX
)
61 /* Check for a value too small to calculate. */
62 if (-z_rooteps_f
< x
&& x
< z_rooteps_f
)
67 /* Calculate the exponent. */
69 N
= (int) (x
* INV_LN2
- 0.5);
71 N
= (int) (x
* INV_LN2
+ 0.5);
73 /* Construct the mantissa. */
76 P
= g
* (p
[1] * z
+ p
[0]);
78 R
= 0.5 + P
/ (Q
- P
);
80 /* Return the floating point value. */
82 return (ldexpf (R
, N
));
85 #ifdef _DOUBLE_IS_32BITS
89 return (double) expf ((float) x
);
92 #endif /* _DOUBLE_IS_32BITS */