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_asine.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_asine.c 1.0 98/08/13 */
/* @(#)z_asine.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
        <<asin>>, <<asinf>>, <<acos>>, <<acosf>>, <<asine>>, <<asinef>>---arc sine or cosine
        <<asin>>, <<asinf>>, <<acos>>, <<acosf>>, <<asine>>, <<asinef>>---arc sine or cosine
 
 
INDEX
INDEX
   asin
   asin
INDEX
INDEX
   asinf
   asinf
INDEX
INDEX
   acos
   acos
INDEX
INDEX
   acosf
   acosf
INDEX
INDEX
   asine
   asine
INDEX
INDEX
   asinef
   asinef
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double asine(double <[x]>);
        double asine(double <[x]>);
        float asinef(float <[x]>);
        float asinef(float <[x]>);
        double asin(double <[x]>);
        double asin(double <[x]>);
        float asinf(float <[x]>);
        float asinf(float <[x]>);
        double acos(double <[x]>);
        double acos(double <[x]>);
        float acosf(float <[x]>);
        float acosf(float <[x]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double asine(<[x]>);
        double asine(<[x]>);
        double <[x]>;
        double <[x]>;
 
 
        float asinef(<[x]>);
        float asinef(<[x]>);
        float <[x]>;
        float <[x]>;
 
 
        double asin(<[x]>)
        double asin(<[x]>)
        double <[x]>;
        double <[x]>;
 
 
        float asinf(<[x]>)
        float asinf(<[x]>)
        float <[x]>;
        float <[x]>;
 
 
        double acos(<[x]>)
        double acos(<[x]>)
        double <[x]>;
        double <[x]>;
 
 
        float acosf(<[x]>)
        float acosf(<[x]>)
        float <[x]>;
        float <[x]>;
 
 
DESCRIPTION
DESCRIPTION
 
 
<<asin>> computes the inverse sine or cosine of the argument <[x]>.
<<asin>> computes the inverse sine or cosine of the argument <[x]>.
Arguments to <<asin>> and <<acos>> must be in the range @minus{}1 to 1.
Arguments to <<asin>> and <<acos>> must be in the range @minus{}1 to 1.
 
 
<<asinf>> and <<acosf>> are identical to <<asin>> and <<acos>>, other
<<asinf>> and <<acosf>> are identical to <<asin>> and <<acos>>, other
than taking and returning floats.
than taking and returning floats.
 
 
RETURNS
RETURNS
@ifnottex
@ifnottex
<<asin>> and <<acos>> return values in radians, in the range of -pi/2 to pi/2.
<<asin>> and <<acos>> return values in radians, in the range of -pi/2 to pi/2.
@end ifnottex
@end ifnottex
@tex
@tex
<<asin>> and <<acos>> return values in radians, in the range of $-\pi/2$ to $\pi/2$.
<<asin>> and <<acos>> return values in radians, in the range of $-\pi/2$ to $\pi/2$.
@end tex
@end tex
 
 
If <[x]> is not in the range @minus{}1 to 1, <<asin>> and <<asinf>>
If <[x]> is not in the range @minus{}1 to 1, <<asin>> and <<asinf>>
return NaN (not a number), set the global variable <<errno>> to
return NaN (not a number), set the global variable <<errno>> to
<<EDOM>>, and issue a <<DOMAIN error>> message.
<<EDOM>>, and issue a <<DOMAIN error>> message.
 
 
*/
*/
 
 
/******************************************************************
/******************************************************************
 * Arcsine
 * Arcsine
 *
 *
 * Input:
 * Input:
 *   x - floating point value
 *   x - floating point value
 *   acosine - indicates acos calculation
 *   acosine - indicates acos calculation
 *
 *
 * Output:
 * Output:
 *   Arcsine of x.
 *   Arcsine of x.
 *
 *
 * Description:
 * Description:
 *   This routine calculates arcsine / arccosine.
 *   This routine calculates arcsine / arccosine.
 *
 *
 *****************************************************************/
 *****************************************************************/
 
 
#include "fdlibm.h"
#include "fdlibm.h"
#include "zmath.h"
#include "zmath.h"
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
static const double p[] = { -0.27368494524164255994e+2,
static const double p[] = { -0.27368494524164255994e+2,
                             0.57208227877891731407e+2,
                             0.57208227877891731407e+2,
                            -0.39688862997404877339e+2,
                            -0.39688862997404877339e+2,
                             0.10152522233806463645e+2,
                             0.10152522233806463645e+2,
                            -0.69674573447350646411 };
                            -0.69674573447350646411 };
static const double q[] = { -0.16421096714498560795e+3,
static const double q[] = { -0.16421096714498560795e+3,
                             0.41714430248260412556e+3,
                             0.41714430248260412556e+3,
                            -0.38186303361750149284e+3,
                            -0.38186303361750149284e+3,
                             0.15095270841030604719e+3,
                             0.15095270841030604719e+3,
                            -0.23823859153670238830e+2 };
                            -0.23823859153670238830e+2 };
static const double a[] = { 0.0, 0.78539816339744830962 };
static const double a[] = { 0.0, 0.78539816339744830962 };
static const double b[] = { 1.57079632679489661923, 0.78539816339744830962 };
static const double b[] = { 1.57079632679489661923, 0.78539816339744830962 };
 
 
double
double
_DEFUN (asine, (double, int),
_DEFUN (asine, (double, int),
        double x _AND
        double x _AND
        int acosine)
        int acosine)
{
{
  int flag, i;
  int flag, i;
  int branch = 0;
  int branch = 0;
  double g, res, R, P, Q, y;
  double g, res, R, P, Q, y;
 
 
  /* Check for special values. */
  /* Check for special values. */
  i = numtest (x);
  i = numtest (x);
  if (i == NAN || i == INF)
  if (i == NAN || i == INF)
    {
    {
      errno = EDOM;
      errno = EDOM;
      if (i == NAN)
      if (i == NAN)
        return (x);
        return (x);
      else
      else
        return (z_infinity.d);
        return (z_infinity.d);
    }
    }
 
 
  y = fabs (x);
  y = fabs (x);
  flag = acosine;
  flag = acosine;
 
 
  if (y > 0.5)
  if (y > 0.5)
    {
    {
      i = 1 - flag;
      i = 1 - flag;
 
 
      /* Check for range error. */
      /* Check for range error. */
      if (y > 1.0)
      if (y > 1.0)
        {
        {
          errno = ERANGE;
          errno = ERANGE;
          return (z_notanum.d);
          return (z_notanum.d);
        }
        }
 
 
      g = (1 - y) / 2.0;
      g = (1 - y) / 2.0;
      y = -2 * sqrt (g);
      y = -2 * sqrt (g);
      branch = 1;
      branch = 1;
    }
    }
  else
  else
    {
    {
      i = flag;
      i = flag;
      if (y < z_rooteps)
      if (y < z_rooteps)
        res = y;
        res = y;
      else
      else
        g = y * y;
        g = y * y;
    }
    }
 
 
  if (y >= z_rooteps || branch == 1)
  if (y >= z_rooteps || branch == 1)
    {
    {
      /* Calculate the Taylor series. */
      /* Calculate the Taylor series. */
      P = ((((p[4] * g + p[3]) * g + p[2]) * g + p[1]) * g + p[0]) * g;
      P = ((((p[4] * g + p[3]) * g + p[2]) * g + p[1]) * g + p[0]) * g;
      Q = ((((g + q[4]) * g + q[3]) * g + q[2]) * g + q[1]) * g + q[0];
      Q = ((((g + q[4]) * g + q[3]) * g + q[2]) * g + q[1]) * g + q[0];
      R = P / Q;
      R = P / Q;
 
 
      res = y + y * R;
      res = y + y * R;
    }
    }
 
 
  /* Calculate asine or acose. */
  /* Calculate asine or acose. */
  if (flag == 0)
  if (flag == 0)
    {
    {
      res = (a[i] + res) + a[i];
      res = (a[i] + res) + a[i];
      if (x < 0.0)
      if (x < 0.0)
        res = -res;
        res = -res;
    }
    }
  else
  else
    {
    {
      if (x < 0.0)
      if (x < 0.0)
        res = (b[i] + res) + b[i];
        res = (b[i] + res) + b[i];
      else
      else
        res = (a[i] - res) + a[i];
        res = (a[i] - res) + a[i];
    }
    }
 
 
  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.