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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 148 jeremybenn
 
2
/* @(#)z_asine.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
        <<asin>>, <<asinf>>, <<acos>>, <<acosf>>, <<asine>>, <<asinef>>---arc sine or cosine
13
 
14
INDEX
15
   asin
16
INDEX
17
   asinf
18
INDEX
19
   acos
20
INDEX
21
   acosf
22
INDEX
23
   asine
24
INDEX
25
   asinef
26
 
27
ANSI_SYNOPSIS
28
        #include <math.h>
29
        double asine(double <[x]>);
30
        float asinef(float <[x]>);
31
        double asin(double <[x]>);
32
        float asinf(float <[x]>);
33
        double acos(double <[x]>);
34
        float acosf(float <[x]>);
35
 
36
TRAD_SYNOPSIS
37
        #include <math.h>
38
        double asine(<[x]>);
39
        double <[x]>;
40
 
41
        float asinef(<[x]>);
42
        float <[x]>;
43
 
44
        double asin(<[x]>)
45
        double <[x]>;
46
 
47
        float asinf(<[x]>)
48
        float <[x]>;
49
 
50
        double acos(<[x]>)
51
        double <[x]>;
52
 
53
        float acosf(<[x]>)
54
        float <[x]>;
55
 
56
DESCRIPTION
57
 
58
<<asin>> computes the inverse sine or cosine of the argument <[x]>.
59
Arguments to <<asin>> and <<acos>> must be in the range @minus{}1 to 1.
60
 
61
<<asinf>> and <<acosf>> are identical to <<asin>> and <<acos>>, other
62
than taking and returning floats.
63
 
64
RETURNS
65
@ifnottex
66
<<asin>> and <<acos>> return values in radians, in the range of -pi/2 to pi/2.
67
@end ifnottex
68
@tex
69
<<asin>> and <<acos>> return values in radians, in the range of $-\pi/2$ to $\pi/2$.
70
@end tex
71
 
72
If <[x]> is not in the range @minus{}1 to 1, <<asin>> and <<asinf>>
73
return NaN (not a number), set the global variable <<errno>> to
74
<<EDOM>>, and issue a <<DOMAIN error>> message.
75
 
76
*/
77
 
78
/******************************************************************
79
 * Arcsine
80
 *
81
 * Input:
82
 *   x - floating point value
83
 *   acosine - indicates acos calculation
84
 *
85
 * Output:
86
 *   Arcsine of x.
87
 *
88
 * Description:
89
 *   This routine calculates arcsine / arccosine.
90
 *
91
 *****************************************************************/
92
 
93
#include "fdlibm.h"
94
#include "zmath.h"
95
 
96
#ifndef _DOUBLE_IS_32BITS
97
 
98
static const double p[] = { -0.27368494524164255994e+2,
99
                             0.57208227877891731407e+2,
100
                            -0.39688862997404877339e+2,
101
                             0.10152522233806463645e+2,
102
                            -0.69674573447350646411 };
103
static const double q[] = { -0.16421096714498560795e+3,
104
                             0.41714430248260412556e+3,
105
                            -0.38186303361750149284e+3,
106
                             0.15095270841030604719e+3,
107
                            -0.23823859153670238830e+2 };
108
static const double a[] = { 0.0, 0.78539816339744830962 };
109
static const double b[] = { 1.57079632679489661923, 0.78539816339744830962 };
110
 
111
double
112
_DEFUN (asine, (double, int),
113
        double x _AND
114
        int acosine)
115
{
116
  int flag, i;
117
  int branch = 0;
118
  double g, res, R, P, Q, y;
119
 
120
  /* Check for special values. */
121
  i = numtest (x);
122
  if (i == NAN || i == INF)
123
    {
124
      errno = EDOM;
125
      if (i == NAN)
126
        return (x);
127
      else
128
        return (z_infinity.d);
129
    }
130
 
131
  y = fabs (x);
132
  flag = acosine;
133
 
134
  if (y > 0.5)
135
    {
136
      i = 1 - flag;
137
 
138
      /* Check for range error. */
139
      if (y > 1.0)
140
        {
141
          errno = ERANGE;
142
          return (z_notanum.d);
143
        }
144
 
145
      g = (1 - y) / 2.0;
146
      y = -2 * sqrt (g);
147
      branch = 1;
148
    }
149
  else
150
    {
151
      i = flag;
152
      if (y < z_rooteps)
153
        res = y;
154
      else
155
        g = y * y;
156
    }
157
 
158
  if (y >= z_rooteps || branch == 1)
159
    {
160
      /* Calculate the Taylor series. */
161
      P = ((((p[4] * g + p[3]) * g + p[2]) * g + p[1]) * g + p[0]) * g;
162
      Q = ((((g + q[4]) * g + q[3]) * g + q[2]) * g + q[1]) * g + q[0];
163
      R = P / Q;
164
 
165
      res = y + y * R;
166
    }
167
 
168
  /* Calculate asine or acose. */
169
  if (flag == 0)
170
    {
171
      res = (a[i] + res) + a[i];
172
      if (x < 0.0)
173
        res = -res;
174
    }
175
  else
176
    {
177
      if (x < 0.0)
178
        res = (b[i] + res) + b[i];
179
      else
180
        res = (a[i] - res) + a[i];
181
    }
182
 
183
  return (res);
184
}
185
 
186
#endif /* _DOUBLE_IS_32BITS */

powered by: WebSVN 2.1.0

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