OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libm/] [mathfp/] [s_tan.c] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
 
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
 ******************************************************************/
9
 
10
/*
11
FUNCTION
12
        <<tan>>, <<tanf>>---tangent
13
 
14
INDEX
15
tan
16
INDEX
17
tanf
18
 
19
ANSI_SYNOPSIS
20
        #include <math.h>
21
        double tan(double <[x]>);
22
        float tanf(float <[x]>);
23
 
24
TRAD_SYNOPSIS
25
        #include <math.h>
26
        double tan(<[x]>)
27
        double <[x]>;
28
 
29
        float tanf(<[x]>)
30
        float <[x]>;
31
 
32
 
33
DESCRIPTION
34
<<tan>> computes the tangent of the argument <[x]>.
35
Angles are specified in radians.
36
 
37
<<tanf>> is identical, save that it takes and returns <<float>> values.
38
 
39
RETURNS
40
The tangent of <[x]> is returned.
41
 
42
PORTABILITY
43
<<tan>> is ANSI. <<tanf>> is an extension.
44
*/
45
 
46
/******************************************************************
47
 * Tangent
48
 *
49
 * Input:
50
 *   x - floating point value
51
 *
52
 * Output:
53
 *   tangent of x
54
 *
55
 * Description:
56
 *   This routine calculates the tangent of x.
57
 *
58
 *****************************************************************/
59
 
60
#include "fdlibm.h"
61
#include "zmath.h"
62
 
63
#ifndef _DOUBLE_IS_32BITS
64
 
65
static const double TWO_OVER_PI = 0.63661977236758134308;
66
static const double p[] = { -0.13338350006421960681,
67
                             0.34248878235890589960e-2,
68
                            -0.17861707342254426711e-4 };
69
static const double q[] = { -0.46671683339755294240,
70
                             0.25663832289440112864e-1,
71
                            -0.31181531907010027307e-3,
72
                             0.49819433993786512270e-6 };
73
 
74
double
75
_DEFUN (tan, (double),
76
        double x)
77
{
78
  double y, f, g, XN, xnum, xden, res;
79
  int N;
80
 
81
  /* Check for special values. */
82
  switch (numtest (x))
83
    {
84
      case NAN:
85
        errno = EDOM;
86
        return (x);
87
      case INF:
88
        errno = EDOM;
89
        return (z_notanum.d);
90
    }
91
 
92
  y = fabs (x);
93
 
94
  /* Check for values that are out of our range. */
95
  if (y > 105414357.0)
96
    {
97
      errno = ERANGE;
98
      return (y);
99
    }
100
 
101
  if (x < 0.0)
102
    N = (int) (x * TWO_OVER_PI - 0.5);
103
  else
104
    N = (int) (x * TWO_OVER_PI + 0.5);
105
 
106
  XN = (double) N;
107
 
108
  f = x - N * __PI_OVER_TWO;
109
 
110
  /* Check for values that are too small. */
111
  if (-z_rooteps < f && f < z_rooteps)
112
    {
113
      xnum = f;
114
      xden = 1.0;
115
    }
116
 
117
  /* Calculate the polynomial. */
118
  else
119
    {
120
      g = f * f;
121
 
122
      xnum = f * ((p[2] * g + p[1]) * g + p[0]) * g + f;
123
      xden = (((q[3] * g + q[2]) * g + q[1]) * g + q[0]) * g + 1.0;
124
    }
125
 
126
  if (N & 1)
127
    {
128
      xnum = -xnum;
129
      res = xden / xnum;
130
    }
131
  else
132
    {
133
      res = xnum / xden;
134
    }
135
 
136
  return (res);
137
}
138
 
139
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.