Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / mathfp / sf_tan.c
blob7924bd2173c3fdb0f7d1aafb1bb111729eee1794
2 /* @(#)z_tanf.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 * Tangent
12 * Input:
13 * x - floating point value
15 * Output:
16 * tangent of x
18 * Description:
19 * This routine calculates the tangent of x.
21 *****************************************************************/
23 #include "fdlibm.h"
24 #include "zmath.h"
26 static const float TWO_OVER_PI = 0.6366197723;
27 static const float p[] = { -0.958017723e-1 };
28 static const float q[] = { -0.429135777,
29 0.971685835e-2 };
31 float
32 tanf (float x)
34 float y, f, g, XN, xnum, xden, res;
35 int N;
37 /* Check for special values. */
38 switch (numtestf (x))
40 case NAN:
41 errno = EDOM;
42 return (x);
43 case INF:
44 errno = EDOM;
45 return (z_notanum_f.f);
48 y = fabsf (x);
50 /* Check for values that are out of our range. */
51 if (y > 105414357.0)
53 errno = ERANGE;
54 return (y);
57 if (x < 0.0)
58 N = (int) (x * TWO_OVER_PI - 0.5);
59 else
60 N = (int) (x * TWO_OVER_PI + 0.5);
62 XN = (float) N;
64 f = x - N * __PI_OVER_TWO;
66 /* Check for values that are too small. */
67 if (-z_rooteps_f < f && f < z_rooteps_f)
69 xnum = f;
70 xden = 1.0;
73 /* Calculate the polynomial. */
74 else
76 g = f * f;
78 xnum = f * (p[0] * g) + f;
79 xden = (q[1] * g + q[0]) * g + 1.0;
82 /* Check for odd or even values. */
83 if (N & 1)
85 xnum = -xnum;
86 res = xden / xnum;
88 else
90 res = xnum / xden;
93 return (res);
96 #ifdef _DOUBLE_IS_32BITS
98 double tan (double x)
100 return (double) tanf ((float) x);
103 #endif /* _DOUBLE_IS_32BITS */