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/] [s_tan.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_tan.c 1.0 98/08/13 */
/* @(#)z_tan.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.
 ******************************************************************/
 ******************************************************************/
 
 
/*
/*
FUNCTION
FUNCTION
        <<tan>>, <<tanf>>---tangent
        <<tan>>, <<tanf>>---tangent
 
 
INDEX
INDEX
tan
tan
INDEX
INDEX
tanf
tanf
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double tan(double <[x]>);
        double tan(double <[x]>);
        float tanf(float <[x]>);
        float tanf(float <[x]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double tan(<[x]>)
        double tan(<[x]>)
        double <[x]>;
        double <[x]>;
 
 
        float tanf(<[x]>)
        float tanf(<[x]>)
        float <[x]>;
        float <[x]>;
 
 
 
 
DESCRIPTION
DESCRIPTION
<<tan>> computes the tangent of the argument <[x]>.
<<tan>> computes the tangent of the argument <[x]>.
Angles are specified in radians.
Angles are specified in radians.
 
 
<<tanf>> is identical, save that it takes and returns <<float>> values.
<<tanf>> is identical, save that it takes and returns <<float>> values.
 
 
RETURNS
RETURNS
The tangent of <[x]> is returned.
The tangent of <[x]> is returned.
 
 
PORTABILITY
PORTABILITY
<<tan>> is ANSI. <<tanf>> is an extension.
<<tan>> is ANSI. <<tanf>> is an extension.
*/
*/
 
 
/******************************************************************
/******************************************************************
 * 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"
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
static const double TWO_OVER_PI = 0.63661977236758134308;
static const double TWO_OVER_PI = 0.63661977236758134308;
static const double p[] = { -0.13338350006421960681,
static const double p[] = { -0.13338350006421960681,
                             0.34248878235890589960e-2,
                             0.34248878235890589960e-2,
                            -0.17861707342254426711e-4 };
                            -0.17861707342254426711e-4 };
static const double q[] = { -0.46671683339755294240,
static const double q[] = { -0.46671683339755294240,
                             0.25663832289440112864e-1,
                             0.25663832289440112864e-1,
                            -0.31181531907010027307e-3,
                            -0.31181531907010027307e-3,
                             0.49819433993786512270e-6 };
                             0.49819433993786512270e-6 };
 
 
double
double
_DEFUN (tan, (double),
_DEFUN (tan, (double),
        double x)
        double x)
{
{
  double y, f, g, XN, xnum, xden, res;
  double y, f, g, XN, xnum, xden, res;
  int N;
  int N;
 
 
  /* Check for special values. */
  /* Check for special values. */
  switch (numtest (x))
  switch (numtest (x))
    {
    {
      case NAN:
      case NAN:
        errno = EDOM;
        errno = EDOM;
        return (x);
        return (x);
      case INF:
      case INF:
        errno = EDOM;
        errno = EDOM;
        return (z_notanum.d);
        return (z_notanum.d);
    }
    }
 
 
  y = fabs (x);
  y = fabs (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 = (double) N;
  XN = (double) 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 < z_rooteps)
  if (-z_rooteps < f && f < z_rooteps)
    {
    {
      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[2] * g + p[1]) * g + p[0]) * g + f;
      xnum = f * ((p[2] * g + p[1]) * g + p[0]) * g + f;
      xden = (((q[3] * g + q[2]) * g + q[1]) * g + q[0]) * g + 1.0;
      xden = (((q[3] * g + q[2]) * g + q[1]) * g + q[0]) * g + 1.0;
    }
    }
 
 
  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);
}
}
 
 
#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.