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/] [sf_sine.c] - Blame information for rev 258

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

Line No. Rev Author Line
1 207 jeremybenn
 
2
/* @(#)z_sinef.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
 * sine generator
11
 *
12
 * Input:
13
 *   x - floating point value
14
 *   cosine - indicates cosine value
15
 *
16
 * Output:
17
 *   Sine of x.
18
 *
19
 * Description:
20
 *   This routine calculates sines and cosines.
21
 *
22
 *****************************************************************/
23
 
24
#include "fdlibm.h"
25
#include "zmath.h"
26
 
27
static const float HALF_PI = 1.570796326;
28
static const float ONE_OVER_PI = 0.318309886;
29
static const float r[] = { -0.1666665668,
30
                            0.8333025139e-02,
31
                           -0.1980741872e-03,
32
                            0.2601903036e-5 };
33
 
34
float
35
_DEFUN (sinef, (float, int),
36
        float x _AND
37
        int cosine)
38
{
39
  int sgn, N;
40
  float y, XN, g, R, res;
41
  float YMAX = 210828714.0;
42
 
43
  switch (numtestf (x))
44
    {
45
      case NAN:
46
        errno = EDOM;
47
        return (x);
48
      case INF:
49
        errno = EDOM;
50
        return (z_notanum_f.f);
51
    }
52
 
53
  /* Use sin and cos properties to ease computations. */
54
  if (cosine)
55
    {
56
      sgn = 1;
57
      y = fabsf (x) + HALF_PI;
58
    }
59
  else
60
    {
61
      if (x < 0.0)
62
        {
63
          sgn = -1;
64
          y = -x;
65
        }
66
      else
67
        {
68
          sgn = 1;
69
          y = x;
70
        }
71
    }
72
 
73
  /* Check for values of y that will overflow here. */
74
  if (y > YMAX)
75
    {
76
      errno = ERANGE;
77
      return (x);
78
    }
79
 
80
  /* Calculate the exponent. */
81
  if (y < 0.0)
82
    N = (int) (y * ONE_OVER_PI - 0.5);
83
  else
84
    N = (int) (y * ONE_OVER_PI + 0.5);
85
  XN = (float) N;
86
 
87
  if (N & 1)
88
    sgn = -sgn;
89
 
90
  if (cosine)
91
    XN -= 0.5;
92
 
93
  y = fabsf (x) - XN * __PI;
94
 
95
  if (-z_rooteps_f < y && y < z_rooteps_f)
96
    res = y;
97
 
98
  else
99
    {
100
      g = y * y;
101
 
102
      /* Calculate the Taylor series. */
103
      R = (((r[3] * g + r[2]) * g + r[1]) * g + r[0]) * g;
104
 
105
      /* Finally, compute the result. */
106
      res = y + y * R;
107
    }
108
 
109
  res *= sgn;
110
 
111
  return (res);
112
}

powered by: WebSVN 2.1.0

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