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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [mathfp/] [sf_atangent.c] - Blame information for rev 853

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

Line No. Rev Author Line
1 148 jeremybenn
 
2
/* @(#)z_atangentf.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
 * Arctangent
11
 *
12
 * Input:
13
 *   x - floating point value
14
 *
15
 * Output:
16
 *   arctangent of x
17
 *
18
 * Description:
19
 *   This routine calculates arctangents.
20
 *
21
 *****************************************************************/
22
 
23
#include <float.h>
24
#include "fdlibm.h"
25
#include "zmath.h"
26
 
27
static const float ROOT3 = 1.732050807;
28
static const float a[] = { 0.0, 0.523598775, 1.570796326,
29
                     1.047197551 };
30
static const float q[] = { 0.1412500740e+1 };
31
static const float p[] = { -0.4708325141, -0.5090958253e-1 };
32
 
33
float
34
_DEFUN (atangentf, (float, float, float, int),
35
        float x _AND
36
        float v _AND
37
        float u _AND
38
        int arctan2)
39
{
40
  float f, g, R, P, Q, A, res;
41
  int N;
42
  int branch = 0;
43
  int expv, expu;
44
 
45
  /* Preparation for calculating arctan2. */
46
  if (arctan2)
47
    {
48
      if (u == 0.0)
49
        if (v == 0.0)
50
          {
51
            errno = ERANGE;
52
            return (z_notanum_f.f);
53
          }
54
        else
55
          {
56
            branch = 1;
57
            res = __PI_OVER_TWO;
58
          }
59
 
60
      if (!branch)
61
        {
62
          int e;
63
          /* Get the exponent values of the inputs. */
64
          g = frexpf (v, &expv);
65
          g = frexpf (u, &expu);
66
 
67
          /* See if a divide will overflow. */
68
          e = expv - expu;
69
          if (e > FLT_MAX_EXP)
70
            {
71
               branch = 1;
72
               res = __PI_OVER_TWO;
73
            }
74
 
75
          /* Also check for underflow. */
76
          else if (e < FLT_MIN_EXP)
77
            {
78
               branch = 2;
79
               res = 0.0;
80
            }
81
         }
82
    }
83
 
84
  if (!branch)
85
    {
86
      if (arctan2)
87
        f = fabsf (v / u);
88
      else
89
        f = fabsf (x);
90
 
91
      if (f > 1.0)
92
        {
93
          f = 1.0 / f;
94
          N = 2;
95
        }
96
      else
97
        N = 0;
98
 
99
      if (f > (2.0 - ROOT3))
100
        {
101
          A = ROOT3 - 1.0;
102
          f = (((A * f - 0.5) - 0.5) + f) / (ROOT3 + f);
103
          N++;
104
        }
105
 
106
      /* Check for values that are too small. */
107
      if (-z_rooteps_f < f && f < z_rooteps_f)
108
        res = f;
109
 
110
      /* Calculate the Taylor series. */
111
      else
112
        {
113
          g = f * f;
114
          P = (p[1] * g + p[0]) * g;
115
          Q = g + q[0];
116
          R = P / Q;
117
 
118
          res = f + f * R;
119
        }
120
 
121
      if (N > 1)
122
        res = -res;
123
 
124
      res += a[N];
125
    }
126
 
127
  if (arctan2)
128
    {
129
      if (u < 0.0)
130
        res = __PI - res;
131
      if (v < 0.0)
132
        res = -res;
133
    }
134
  else if (x < 0.0)
135
    {
136
      res = -res;
137
    }
138
 
139
  return (res);
140
}

powered by: WebSVN 2.1.0

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