Back to index

glibc  2.9
Defines | Functions | Variables
e_expf.c File Reference
#include <float.h>
#include <ieee754.h>
#include <math.h>
#include <fenv.h>
#include <inttypes.h>
#include <math_private.h>

Go to the source code of this file.

Defines

#define _GNU_SOURCE

Functions

float __ieee754_expf (float x)

Variables

const float __exp_deltatable [178]
const double __exp_atable [355]
static const volatile float TWOM100 = 7.88860905e-31
static const volatile float TWO127 = 1.7014118346e+38

Define Documentation

#define _GNU_SOURCE

Definition at line 51 of file e_expf.c.


Function Documentation

float __ieee754_expf ( float  x)

Definition at line 67 of file e_expf.c.

{
  static const float himark = 88.72283935546875;
  static const float lomark = -103.972084045410;
  /* Check for usual case.  */
  if (isless (x, himark) && isgreater (x, lomark))
    {
      static const float THREEp42 = 13194139533312.0;
      static const float THREEp22 = 12582912.0;
      /* 1/ln(2).  */
#undef M_1_LN2
      static const float M_1_LN2 = 1.44269502163f;
      /* ln(2) */
#undef M_LN2
      static const double M_LN2 = .6931471805599452862;

      int tval;
      double x22, t, result, dx;
      float n, delta;
      union ieee754_double ex2_u;
      fenv_t oldenv;

      feholdexcept (&oldenv);
#ifdef FE_TONEAREST
      fesetround (FE_TONEAREST);
#endif

      /* Calculate n.  */
      n = x * M_1_LN2 + THREEp22;
      n -= THREEp22;
      dx = x - n*M_LN2;

      /* Calculate t/512.  */
      t = dx + THREEp42;
      t -= THREEp42;
      dx -= t;

      /* Compute tval = t.  */
      tval = (int) (t * 512.0);

      if (t >= 0)
       delta = - __exp_deltatable[tval];
      else
       delta = __exp_deltatable[-tval];

      /* Compute ex2 = 2^n e^(t/512+delta[t]).  */
      ex2_u.d = __exp_atable[tval+177];
      ex2_u.ieee.exponent += (int) n;

      /* Approximate e^(dx+delta) - 1, using a second-degree polynomial,
        with maximum error in [-2^-10-2^-28,2^-10+2^-28]
        less than 5e-11.  */
      x22 = (0.5000000496709180453 * dx + 1.0000001192102037084) * dx + delta;

      /* Return result.  */
      fesetenv (&oldenv);

      result = x22 * ex2_u.d + ex2_u.d;
      return (float) result;
    }
  /* Exceptional cases:  */
  else if (isless (x, himark))
    {
      if (__isinff (x))
       /* e^-inf == 0, with no error.  */
       return 0;
      else
       /* Underflow */
       return TWOM100 * TWOM100;
    }
  else
    /* Return x, if x is a NaN or Inf; or overflow, otherwise.  */
    return TWO127*x;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const double __exp_atable[355]

Definition at line 80 of file t_exp.c.

const float __exp_deltatable[178]

Definition at line 32 of file t_exp.c.

const volatile float TWO127 = 1.7014118346e+38 [static]

Definition at line 64 of file e_expf.c.

const volatile float TWOM100 = 7.88860905e-31 [static]

Definition at line 63 of file e_expf.c.