Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / mathfp / sf_exp.c
blob33b3529c87b4710d2ddaf761c3f4d97af288c474
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
7 * Hall, 1980.
8 ******************************************************************/
9 /******************************************************************
10 * Exponential Function
12 * Input:
13 * x - floating point value
15 * Output:
16 * e raised to x.
18 * Description:
19 * This routine returns e raised to the xth power.
21 *****************************************************************/
23 #include <float.h>
24 #include "fdlibm.h"
25 #include "zmath.h"
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 };
32 float
33 expf (float x)
35 int N;
36 float g, z, R, P, Q;
38 switch (numtestf (x))
40 case NAN:
41 errno = EDOM;
42 return (x);
43 case INF:
44 errno = ERANGE;
45 if (isposf (x))
46 return (z_infinity_f.f);
47 else
48 return (0.0);
49 case 0:
50 return (1.0);
53 /* Check for out of bounds. */
54 if (x > BIGX || x < SMALLX)
56 errno = ERANGE;
57 return (x);
60 /* Check for a value too small to calculate. */
61 if (-z_rooteps_f < x && x < z_rooteps_f)
63 return (1.0);
66 /* Calculate the exponent. */
67 if (x < 0.0)
68 N = (int) (x * INV_LN2 - 0.5);
69 else
70 N = (int) (x * INV_LN2 + 0.5);
72 /* Construct the mantissa. */
73 g = x - N * LN2;
74 z = g * g;
75 P = g * (p[1] * z + p[0]);
76 Q = q[1] * z + q[0];
77 R = 0.5 + P / (Q - P);
79 /* Return the floating point value. */
80 N++;
81 return (ldexpf (R, N));
84 #ifdef _DOUBLE_IS_32BITS
86 double exp (double x)
88 return (double) expf ((float) x);
91 #endif /* _DOUBLE_IS_32BITS */