Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / mathfp / s_tan.c
blobf3bfb698892140674cf1571ad5abb15a96069bd5
2 /* @(#)z_tan.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 ******************************************************************/
11 FUNCTION
12 <<tan>>, <<tanf>>---tangent
14 INDEX
15 tan
16 INDEX
17 tanf
19 SYNOPSIS
20 #include <math.h>
21 double tan(double <[x]>);
22 float tanf(float <[x]>);
24 DESCRIPTION
25 <<tan>> computes the tangent of the argument <[x]>.
26 Angles are specified in radians.
28 <<tanf>> is identical, save that it takes and returns <<float>> values.
30 RETURNS
31 The tangent of <[x]> is returned.
33 PORTABILITY
34 <<tan>> is ANSI. <<tanf>> is an extension.
37 /******************************************************************
38 * Tangent
40 * Input:
41 * x - floating point value
43 * Output:
44 * tangent of x
46 * Description:
47 * This routine calculates the tangent of x.
49 *****************************************************************/
51 #include "fdlibm.h"
52 #include "zmath.h"
54 #ifndef _DOUBLE_IS_32BITS
56 static const double TWO_OVER_PI = 0.63661977236758134308;
57 static const double p[] = { -0.13338350006421960681,
58 0.34248878235890589960e-2,
59 -0.17861707342254426711e-4 };
60 static const double q[] = { -0.46671683339755294240,
61 0.25663832289440112864e-1,
62 -0.31181531907010027307e-3,
63 0.49819433993786512270e-6 };
65 double
66 tan (double x)
68 double y, f, g, XN, xnum, xden, res;
69 int N;
71 /* Check for special values. */
72 switch (numtest (x))
74 case NAN:
75 errno = EDOM;
76 return (x);
77 case INF:
78 errno = EDOM;
79 return (z_notanum.d);
82 y = fabs (x);
84 /* Check for values that are out of our range. */
85 if (y > 105414357.0)
87 errno = ERANGE;
88 return (y);
91 if (x < 0.0)
92 N = (int) (x * TWO_OVER_PI - 0.5);
93 else
94 N = (int) (x * TWO_OVER_PI + 0.5);
96 XN = (double) N;
98 f = x - N * __PI_OVER_TWO;
100 /* Check for values that are too small. */
101 if (-z_rooteps < f && f < z_rooteps)
103 xnum = f;
104 xden = 1.0;
107 /* Calculate the polynomial. */
108 else
110 g = f * f;
112 xnum = f * ((p[2] * g + p[1]) * g + p[0]) * g + f;
113 xden = (((q[3] * g + q[2]) * g + q[1]) * g + q[0]) * g + 1.0;
116 if (N & 1)
118 xnum = -xnum;
119 res = xden / xnum;
121 else
123 res = xnum / xden;
126 return (res);
129 #endif /* _DOUBLE_IS_32BITS */