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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libm/] [mathfp/] [s_sineh.c] - Diff between revs 148 and 158

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

Rev 148 Rev 158
 
 
/* @(#)z_sineh.c 1.0 98/08/13 */
/* @(#)z_sineh.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
        <<sinh>>, <<sinhf>>, <<cosh>>, <<coshf>>, <<sineh>>---hyperbolic sine or cosine
        <<sinh>>, <<sinhf>>, <<cosh>>, <<coshf>>, <<sineh>>---hyperbolic sine or cosine
 
 
INDEX
INDEX
        sinh
        sinh
INDEX
INDEX
        sinhf
        sinhf
INDEX
INDEX
        cosh
        cosh
INDEX
INDEX
        coshf
        coshf
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double sinh(double <[x]>);
        double sinh(double <[x]>);
        float  sinhf(float <[x]>);
        float  sinhf(float <[x]>);
        double cosh(double <[x]>);
        double cosh(double <[x]>);
        float  coshf(float <[x]>);
        float  coshf(float <[x]>);
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double sinh(<[x]>)
        double sinh(<[x]>)
        double <[x]>;
        double <[x]>;
 
 
        float  sinhf(<[x]>)
        float  sinhf(<[x]>)
        float <[x]>;
        float <[x]>;
 
 
        double cosh(<[x]>)
        double cosh(<[x]>)
        double <[x]>;
        double <[x]>;
 
 
        float  coshf(<[x]>)
        float  coshf(<[x]>)
        float <[x]>;
        float <[x]>;
 
 
DESCRIPTION
DESCRIPTION
        <<sinh>> and <<cosh>> compute the hyperbolic sine or cosine
        <<sinh>> and <<cosh>> compute the hyperbolic sine or cosine
        of the argument <[x]>.
        of the argument <[x]>.
        Angles are specified in radians.   <<sinh>>(<[x]>) is defined as
        Angles are specified in radians.   <<sinh>>(<[x]>) is defined as
        @ifnottex
        @ifnottex
        . (exp(<[x]>) - exp(-<[x]>))/2
        . (exp(<[x]>) - exp(-<[x]>))/2
        @end ifnottex
        @end ifnottex
        @tex
        @tex
        $${e^x - e^{-x}}\over 2$$
        $${e^x - e^{-x}}\over 2$$
        @end tex
        @end tex
        <<cosh>> is defined as
        <<cosh>> is defined as
        @ifnottex
        @ifnottex
        . (exp(<[x]>) - exp(-<[x]>))/2
        . (exp(<[x]>) - exp(-<[x]>))/2
        @end ifnottex
        @end ifnottex
        @tex
        @tex
        $${e^x + e^{-x}}\over 2$$
        $${e^x + e^{-x}}\over 2$$
        @end tex
        @end tex
 
 
        <<sinhf>> and <<coshf>> are identical, save that they take
        <<sinhf>> and <<coshf>> are identical, save that they take
        and returns <<float>> values.
        and returns <<float>> values.
 
 
RETURNS
RETURNS
        The hyperbolic sine or cosine of <[x]> is returned.
        The hyperbolic sine or cosine of <[x]> is returned.
 
 
        When the correct result is too large to be representable (an
        When the correct result is too large to be representable (an
        overflow),  the functions return <<HUGE_VAL>> with the
        overflow),  the functions return <<HUGE_VAL>> with the
        appropriate sign, and sets the global value <<errno>> to
        appropriate sign, and sets the global value <<errno>> to
        <<ERANGE>>.
        <<ERANGE>>.
 
 
PORTABILITY
PORTABILITY
        <<sinh>> is ANSI C.
        <<sinh>> is ANSI C.
        <<sinhf>> is an extension.
        <<sinhf>> is an extension.
        <<cosh>> is ANSI C.
        <<cosh>> is ANSI C.
        <<coshf>> is an extension.
        <<coshf>> is an extension.
 
 
*/
*/
 
 
/******************************************************************
/******************************************************************
 * Hyperbolic Sine
 * Hyperbolic Sine
 *
 *
 * Input:
 * Input:
 *   x - floating point value
 *   x - floating point value
 *
 *
 * Output:
 * Output:
 *   hyperbolic sine of x
 *   hyperbolic sine of x
 *
 *
 * Description:
 * Description:
 *   This routine calculates hyperbolic sines.
 *   This routine calculates hyperbolic sines.
 *
 *
 *****************************************************************/
 *****************************************************************/
 
 
#include <float.h>
#include <float.h>
#include "fdlibm.h"
#include "fdlibm.h"
#include "zmath.h"
#include "zmath.h"
 
 
static const double q[] = { -0.21108770058106271242e+7,
static const double q[] = { -0.21108770058106271242e+7,
                             0.36162723109421836460e+5,
                             0.36162723109421836460e+5,
                            -0.27773523119650701667e+3 };
                            -0.27773523119650701667e+3 };
static const double p[] = { -0.35181283430177117881e+6,
static const double p[] = { -0.35181283430177117881e+6,
                            -0.11563521196851768270e+5,
                            -0.11563521196851768270e+5,
                            -0.16375798202630751372e+3,
                            -0.16375798202630751372e+3,
                            -0.78966127417357099479 };
                            -0.78966127417357099479 };
static const double LNV = 0.6931610107421875000;
static const double LNV = 0.6931610107421875000;
static const double INV_V2 = 0.24999308500451499336;
static const double INV_V2 = 0.24999308500451499336;
static const double V_OVER2_MINUS1 = 0.13830277879601902638e-4;
static const double V_OVER2_MINUS1 = 0.13830277879601902638e-4;
 
 
double
double
_DEFUN (sineh, (double, int),
_DEFUN (sineh, (double, int),
        double x _AND
        double x _AND
        int cosineh)
        int cosineh)
{
{
  double y, f, P, Q, R, res, z, w;
  double y, f, P, Q, R, res, z, w;
  int sgn = 1;
  int sgn = 1;
  double WBAR = 18.55;
  double WBAR = 18.55;
 
 
  /* 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 = ERANGE;
        errno = ERANGE;
        return (ispos (x) ? z_infinity.d : -z_infinity.d);
        return (ispos (x) ? z_infinity.d : -z_infinity.d);
    }
    }
 
 
  y = fabs (x);
  y = fabs (x);
 
 
  if (!cosineh && x < 0.0)
  if (!cosineh && x < 0.0)
    sgn = -1;
    sgn = -1;
 
 
  if ((y > 1.0 && !cosineh) || cosineh)
  if ((y > 1.0 && !cosineh) || cosineh)
    {
    {
      if (y > BIGX)
      if (y > BIGX)
        {
        {
          w = y - LNV;
          w = y - LNV;
 
 
          /* Check for w > maximum here. */
          /* Check for w > maximum here. */
          if (w > BIGX)
          if (w > BIGX)
            {
            {
              errno = ERANGE;
              errno = ERANGE;
              return (x);
              return (x);
            }
            }
 
 
          z = exp (w);
          z = exp (w);
 
 
          if (w > WBAR)
          if (w > WBAR)
            res = z * (V_OVER2_MINUS1 + 1.0);
            res = z * (V_OVER2_MINUS1 + 1.0);
        }
        }
 
 
      else
      else
        {
        {
          z = exp (y);
          z = exp (y);
          if (cosineh)
          if (cosineh)
            res = (z + 1 / z) / 2.0;
            res = (z + 1 / z) / 2.0;
          else
          else
            res = (z - 1 / z) / 2.0;
            res = (z - 1 / z) / 2.0;
        }
        }
 
 
      if (sgn < 0)
      if (sgn < 0)
        res = -res;
        res = -res;
    }
    }
  else
  else
    {
    {
      /* Check for y being too small. */
      /* Check for y being too small. */
      if (y < z_rooteps)
      if (y < z_rooteps)
        {
        {
          res = x;
          res = x;
        }
        }
      /* Calculate the Taylor series. */
      /* Calculate the Taylor series. */
      else
      else
        {
        {
          f = x * x;
          f = x * x;
          Q = ((f + q[2]) * f + q[1]) * f + q[0];
          Q = ((f + q[2]) * f + q[1]) * f + q[0];
          P = ((p[3] * f + p[2]) * f + p[1]) * f + p[0];
          P = ((p[3] * f + p[2]) * f + p[1]) * f + p[0];
          R = f * (P / Q);
          R = f * (P / Q);
 
 
          res = x + x * R;
          res = x + x * R;
        }
        }
    }
    }
 
 
  return (res);
  return (res);
}
}
 
 

powered by: WebSVN 2.1.0

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