OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
 
 
/* @(#)z_tanf.c 1.0 98/08/13 */
/* @(#)z_tanf.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.
 ******************************************************************/
 ******************************************************************/
/******************************************************************
/******************************************************************
 * Tangent
 * Tangent
 *
 *
 * Input:
 * Input:
 *   x - floating point value
 *   x - floating point value
 *
 *
 * Output:
 * Output:
 *   tangent of x
 *   tangent of x
 *
 *
 * Description:
 * Description:
 *   This routine calculates the tangent of x.
 *   This routine calculates the tangent of x.
 *
 *
 *****************************************************************/
 *****************************************************************/
 
 
#include "fdlibm.h"
#include "fdlibm.h"
#include "zmath.h"
#include "zmath.h"
 
 
static const float TWO_OVER_PI = 0.6366197723;
static const float TWO_OVER_PI = 0.6366197723;
static const float p[] = { -0.958017723e-1 };
static const float p[] = { -0.958017723e-1 };
static const float q[] = { -0.429135777,
static const float q[] = { -0.429135777,
                            0.971685835e-2 };
                            0.971685835e-2 };
 
 
float
float
_DEFUN (tanf, (float),
_DEFUN (tanf, (float),
        float x)
        float x)
{
{
  float y, f, g, XN, xnum, xden, res;
  float y, f, g, XN, xnum, xden, res;
  int N;
  int N;
 
 
  /* Check for special values. */
  /* Check for special values. */
  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);
    }
    }
 
 
  y = fabsf (x);
  y = fabsf (x);
 
 
  /* Check for values that are out of our range. */
  /* Check for values that are out of our range. */
  if (y > 105414357.0)
  if (y > 105414357.0)
    {
    {
      errno = ERANGE;
      errno = ERANGE;
      return (y);
      return (y);
    }
    }
 
 
  if (x < 0.0)
  if (x < 0.0)
    N = (int) (x * TWO_OVER_PI - 0.5);
    N = (int) (x * TWO_OVER_PI - 0.5);
  else
  else
    N = (int) (x * TWO_OVER_PI + 0.5);
    N = (int) (x * TWO_OVER_PI + 0.5);
 
 
  XN = (float) N;
  XN = (float) N;
 
 
  f = x - N * __PI_OVER_TWO;
  f = x - N * __PI_OVER_TWO;
 
 
  /* Check for values that are too small. */
  /* Check for values that are too small. */
  if (-z_rooteps_f < f && f < z_rooteps_f)
  if (-z_rooteps_f < f && f < z_rooteps_f)
    {
    {
      xnum = f;
      xnum = f;
      xden = 1.0;
      xden = 1.0;
    }
    }
 
 
  /* Calculate the polynomial. */
  /* Calculate the polynomial. */
  else
  else
    {
    {
      g = f * f;
      g = f * f;
 
 
      xnum = f * (p[0] * g) + f;
      xnum = f * (p[0] * g) + f;
      xden = (q[1] * g + q[0]) * g + 1.0;
      xden = (q[1] * g + q[0]) * g + 1.0;
    }
    }
 
 
  /* Check for odd or even values. */
  /* Check for odd or even values. */
  if (N & 1)
  if (N & 1)
    {
    {
      xnum = -xnum;
      xnum = -xnum;
      res = xden / xnum;
      res = xden / xnum;
    }
    }
  else
  else
    {
    {
      res = xnum / xden;
      res = xnum / xden;
    }
    }
 
 
  return (res);
  return (res);
}
}
 
 
#ifdef _DOUBLE_IS_32BITS
#ifdef _DOUBLE_IS_32BITS
 
 
double tan (double x)
double tan (double x)
{
{
  return (double) tanf ((float) x);
  return (double) tanf ((float) x);
}
}
 
 
#endif /* _DOUBLE_IS_32BITS */
#endif /* _DOUBLE_IS_32BITS */
 
 

powered by: WebSVN 2.1.0

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