source: trunk/libs/newlib/src/newlib/libm/mathfp/sf_tan.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.0 KB
Line 
1
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
11 *
12 * Input:
13 *   x - floating point value
14 *
15 * Output:
16 *   tangent of x
17 *
18 * Description:
19 *   This routine calculates the tangent of x.
20 *
21 *****************************************************************/
22
23#include "fdlibm.h"
24#include "zmath.h"
25
26static const float TWO_OVER_PI = 0.6366197723;
27static const float p[] = { -0.958017723e-1 };
28static const float q[] = { -0.429135777,
29                            0.971685835e-2 };
30
31float
32tanf (float x)
33{
34  float y, f, g, XN, xnum, xden, res;
35  int N;
36
37  /* Check for special values. */
38  switch (numtestf (x))
39    {
40      case NAN:
41        errno = EDOM;
42        return (x);
43      case INF:
44        errno = EDOM;
45        return (z_notanum_f.f);
46    }
47
48  y = fabsf (x);
49
50  /* Check for values that are out of our range. */
51  if (y > 105414357.0)
52    {
53      errno = ERANGE;
54      return (y);
55    }
56
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);
61
62  XN = (float) N;
63
64  f = x - N * __PI_OVER_TWO;
65
66  /* Check for values that are too small. */
67  if (-z_rooteps_f < f && f < z_rooteps_f)
68    {
69      xnum = f;
70      xden = 1.0;
71    }
72
73  /* Calculate the polynomial. */ 
74  else
75    { 
76      g = f * f;
77
78      xnum = f * (p[0] * g) + f;
79      xden = (q[1] * g + q[0]) * g + 1.0;
80    }
81
82  /* Check for odd or even values. */
83  if (N & 1)
84    {
85      xnum = -xnum;
86      res = xden / xnum;
87    } 
88  else
89    {
90      res = xnum / xden;
91    }
92
93  return (res);
94}
95
96#ifdef _DOUBLE_IS_32BITS
97
98double tan (double x)
99{
100  return (double) tanf ((float) x);
101}
102
103#endif /* _DOUBLE_IS_32BITS */
Note: See TracBrowser for help on using the repository browser.