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_exp.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_expf.c 1.0 98/08/13 */
/* @(#)z_expf.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.
 ******************************************************************/
 ******************************************************************/
/******************************************************************
/******************************************************************
 * Exponential Function
 * Exponential Function
 *
 *
 * Input:
 * Input:
 *   x - floating point value
 *   x - floating point value
 *
 *
 * Output:
 * Output:
 *   e raised to x.
 *   e raised to x.
 *
 *
 * Description:
 * Description:
 *   This routine returns e raised to the xth power.
 *   This routine returns e raised to the xth power.
 *
 *
 *****************************************************************/
 *****************************************************************/
 
 
#include <float.h>
#include <float.h>
#include "fdlibm.h"
#include "fdlibm.h"
#include "zmath.h"
#include "zmath.h"
 
 
static const float INV_LN2 = 1.442695040;
static const float INV_LN2 = 1.442695040;
static const float LN2 = 0.693147180;
static const float LN2 = 0.693147180;
static const float p[] = { 0.249999999950, 0.00416028863 };
static const float p[] = { 0.249999999950, 0.00416028863 };
static const float q[] = { 0.5, 0.04998717878 };
static const float q[] = { 0.5, 0.04998717878 };
 
 
float
float
_DEFUN (expf, (float),
_DEFUN (expf, (float),
        float x)
        float x)
{
{
  int N;
  int N;
  float g, z, R, P, Q;
  float g, z, R, P, Q;
 
 
  switch (numtestf (x))
  switch (numtestf (x))
    {
    {
      case NAN:
      case NAN:
        errno = EDOM;
        errno = EDOM;
        return (x);
        return (x);
      case INF:
      case INF:
        errno = ERANGE;
        errno = ERANGE;
        if (isposf (x))
        if (isposf (x))
          return (z_infinity_f.f);
          return (z_infinity_f.f);
        else
        else
          return (0.0);
          return (0.0);
      case 0:
      case 0:
        return (1.0);
        return (1.0);
    }
    }
 
 
  /* Check for out of bounds. */
  /* Check for out of bounds. */
  if (x > BIGX || x < SMALLX)
  if (x > BIGX || x < SMALLX)
    {
    {
      errno = ERANGE;
      errno = ERANGE;
      return (x);
      return (x);
    }
    }
 
 
  /* Check for a value too small to calculate. */
  /* Check for a value too small to calculate. */
  if (-z_rooteps_f < x && x < z_rooteps_f)
  if (-z_rooteps_f < x && x < z_rooteps_f)
    {
    {
      return (1.0);
      return (1.0);
    }
    }
 
 
  /* Calculate the exponent. */
  /* Calculate the exponent. */
  if (x < 0.0)
  if (x < 0.0)
    N = (int) (x * INV_LN2 - 0.5);
    N = (int) (x * INV_LN2 - 0.5);
  else
  else
    N = (int) (x * INV_LN2 + 0.5);
    N = (int) (x * INV_LN2 + 0.5);
 
 
  /* Construct the mantissa. */
  /* Construct the mantissa. */
  g = x - N * LN2;
  g = x - N * LN2;
  z = g * g;
  z = g * g;
  P = g * (p[1] * z + p[0]);
  P = g * (p[1] * z + p[0]);
  Q = q[1] * z + q[0];
  Q = q[1] * z + q[0];
  R = 0.5 + P / (Q - P);
  R = 0.5 + P / (Q - P);
 
 
  /* Return the floating point value. */
  /* Return the floating point value. */
  N++;
  N++;
  return (ldexpf (R, N));
  return (ldexpf (R, N));
}
}
 
 
#ifdef _DOUBLE_IS_32BITS
#ifdef _DOUBLE_IS_32BITS
 
 
double exp (double x)
double exp (double x)
{
{
  return (double) expf ((float) x);
  return (double) expf ((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.