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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [mathfp/] [sf_sine.c] - Diff between revs 207 and 345

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
 
 
/* @(#)z_sinef.c 1.0 98/08/13 */
/* @(#)z_sinef.c 1.0 98/08/13 */
/******************************************************************
/******************************************************************
 * The following routines are coded directly from the algorithms
 * The following routines are coded directly from the algorithms
 * and coefficients given in "Software Manual for the Elementary
 * and coefficients given in "Software Manual for the Elementary
 * Functions" by William J. Cody, Jr. and William Waite, Prentice
 * Functions" by William J. Cody, Jr. and William Waite, Prentice
 * Hall, 1980.
 * Hall, 1980.
 ******************************************************************/
 ******************************************************************/
/******************************************************************
/******************************************************************
 * sine generator
 * sine generator
 *
 *
 * Input:
 * Input:
 *   x - floating point value
 *   x - floating point value
 *   cosine - indicates cosine value
 *   cosine - indicates cosine value
 *
 *
 * Output:
 * Output:
 *   Sine of x.
 *   Sine of x.
 *
 *
 * Description:
 * Description:
 *   This routine calculates sines and cosines.
 *   This routine calculates sines and cosines.
 *
 *
 *****************************************************************/
 *****************************************************************/
 
 
#include "fdlibm.h"
#include "fdlibm.h"
#include "zmath.h"
#include "zmath.h"
 
 
static const float HALF_PI = 1.570796326;
static const float HALF_PI = 1.570796326;
static const float ONE_OVER_PI = 0.318309886;
static const float ONE_OVER_PI = 0.318309886;
static const float r[] = { -0.1666665668,
static const float r[] = { -0.1666665668,
                            0.8333025139e-02,
                            0.8333025139e-02,
                           -0.1980741872e-03,
                           -0.1980741872e-03,
                            0.2601903036e-5 };
                            0.2601903036e-5 };
 
 
float
float
_DEFUN (sinef, (float, int),
_DEFUN (sinef, (float, int),
        float x _AND
        float x _AND
        int cosine)
        int cosine)
{
{
  int sgn, N;
  int sgn, N;
  float y, XN, g, R, res;
  float y, XN, g, R, res;
  float YMAX = 210828714.0;
  float YMAX = 210828714.0;
 
 
  switch (numtestf (x))
  switch (numtestf (x))
    {
    {
      case NAN:
      case NAN:
        errno = EDOM;
        errno = EDOM;
        return (x);
        return (x);
      case INF:
      case INF:
        errno = EDOM;
        errno = EDOM;
        return (z_notanum_f.f);
        return (z_notanum_f.f);
    }
    }
 
 
  /* Use sin and cos properties to ease computations. */
  /* Use sin and cos properties to ease computations. */
  if (cosine)
  if (cosine)
    {
    {
      sgn = 1;
      sgn = 1;
      y = fabsf (x) + HALF_PI;
      y = fabsf (x) + HALF_PI;
    }
    }
  else
  else
    {
    {
      if (x < 0.0)
      if (x < 0.0)
        {
        {
          sgn = -1;
          sgn = -1;
          y = -x;
          y = -x;
        }
        }
      else
      else
        {
        {
          sgn = 1;
          sgn = 1;
          y = x;
          y = x;
        }
        }
    }
    }
 
 
  /* Check for values of y that will overflow here. */
  /* Check for values of y that will overflow here. */
  if (y > YMAX)
  if (y > YMAX)
    {
    {
      errno = ERANGE;
      errno = ERANGE;
      return (x);
      return (x);
    }
    }
 
 
  /* Calculate the exponent. */
  /* Calculate the exponent. */
  if (y < 0.0)
  if (y < 0.0)
    N = (int) (y * ONE_OVER_PI - 0.5);
    N = (int) (y * ONE_OVER_PI - 0.5);
  else
  else
    N = (int) (y * ONE_OVER_PI + 0.5);
    N = (int) (y * ONE_OVER_PI + 0.5);
  XN = (float) N;
  XN = (float) N;
 
 
  if (N & 1)
  if (N & 1)
    sgn = -sgn;
    sgn = -sgn;
 
 
  if (cosine)
  if (cosine)
    XN -= 0.5;
    XN -= 0.5;
 
 
  y = fabsf (x) - XN * __PI;
  y = fabsf (x) - XN * __PI;
 
 
  if (-z_rooteps_f < y && y < z_rooteps_f)
  if (-z_rooteps_f < y && y < z_rooteps_f)
    res = y;
    res = y;
 
 
  else
  else
    {
    {
      g = y * y;
      g = y * y;
 
 
      /* Calculate the Taylor series. */
      /* Calculate the Taylor series. */
      R = (((r[3] * g + r[2]) * g + r[1]) * g + r[0]) * g;
      R = (((r[3] * g + r[2]) * g + r[1]) * g + r[0]) * g;
 
 
      /* Finally, compute the result. */
      /* Finally, compute the result. */
      res = y + y * R;
      res = y + y * R;
    }
    }
 
 
  res *= sgn;
  res *= sgn;
 
 
  return (res);
  return (res);
}
}
 
 

powered by: WebSVN 2.1.0

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