2 /* @(#)z_exp.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 ******************************************************************/
12 <<exp>>, <<expf>>---exponential
20 double exp(double <[x]>);
21 float expf(float <[x]>);
24 <<exp>> and <<expf>> calculate the exponential of <[x]>, that is,
26 e raised to the power <[x]> (where e
31 is the base of the natural system of logarithms, approximately 2.71828).
34 On success, <<exp>> and <<expf>> return the calculated value.
35 If the result underflows, the returned value is <<0>>. If the
36 result overflows, the returned value is <<HUGE_VAL>>. In
37 either case, <<errno>> is set to <<ERANGE>>.
40 <<exp>> is ANSI C. <<expf>> is an extension.
44 /*****************************************************************
45 * Exponential Function
48 * x - floating point value
54 * This routine returns e raised to the xth power.
56 *****************************************************************/
62 #ifndef _DOUBLE_IS_32BITS
64 static const double INV_LN2
= 1.4426950408889634074;
65 static const double LN2
= 0.6931471805599453094172321;
66 static const double p
[] = { 0.25, 0.75753180159422776666e-2,
67 0.31555192765684646356e-4 };
68 static const double q
[] = { 0.5, 0.56817302698551221787e-1,
69 0.63121894374398504557e-3,
70 0.75104028399870046114e-6 };
86 return (z_infinity
.d
);
93 /* Check for out of bounds. */
94 if (x
> BIGX
|| x
< SMALLX
)
100 /* Check for a value too small to calculate. */
101 if (-z_rooteps
< x
&& x
< z_rooteps
)
106 /* Calculate the exponent. */
108 N
= (int) (x
* INV_LN2
- 0.5);
110 N
= (int) (x
* INV_LN2
+ 0.5);
112 /* Construct the mantissa. */
115 P
= g
* ((p
[2] * z
+ p
[1]) * z
+ p
[0]);
116 Q
= ((q
[3] * z
+ q
[2]) * z
+ q
[1]) * z
+ q
[0];
117 R
= 0.5 + P
/ (Q
- P
);
119 /* Return the floating point value. */
121 return (ldexp (R
, N
));
124 #endif /* _DOUBLE_IS_32BITS */