SDL  2.0
e_exp.c File Reference
#include "math_libm.h"
#include "math_private.h"
+ Include dependency graph for e_exp.c:

Go to the source code of this file.

Functions

double __ieee754_exp (double x)
 

Variables

static const double one = 1.0
 
static const double halF [2] = {0.5,-0.5,}
 
static const double huge = 1.0e+300
 
static const double twom1000 = 9.33263618503218878990e-302
 
static const double o_threshold = 7.09782712893383973096e+02
 
static const double u_threshold = -7.45133219101941108420e+02
 
static const double ln2HI [2]
 
static const double ln2LO [2]
 
static const double invln2 = 1.44269504088896338700e+00
 
static const double P1 = 1.66666666666666019037e-01
 
static const double P2 = -2.77777777770155933842e-03
 
static const double P3 = 6.61375632143793436117e-05
 
static const double P4 = -1.65339022054652515390e-06
 
static const double P5 = 4.13813679705723846039e-08
 

Function Documentation

◆ __ieee754_exp()

double __ieee754_exp ( double  x)

Definition at line 100 of file e_exp.c.

101 {
102  double y;
103  double hi = 0.0;
104  double lo = 0.0;
105  double c;
106  double t;
107  int32_t k=0;
108  int32_t xsb;
109  u_int32_t hx;
110 
111  GET_HIGH_WORD(hx,x);
112  xsb = (hx>>31)&1; /* sign bit of x */
113  hx &= 0x7fffffff; /* high word of |x| */
114 
115  /* filter out non-finite argument */
116  if(hx >= 0x40862E42) { /* if |x|>=709.78... */
117  if(hx>=0x7ff00000) {
118  u_int32_t lx;
119  GET_LOW_WORD(lx,x);
120  if(((hx&0xfffff)|lx)!=0)
121  return x+x; /* NaN */
122  else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
123  }
124  #if 1
125  if(x > o_threshold) return huge*huge; /* overflow */
126  #else /* !!! FIXME: check this: "huge * huge" is a compiler warning, maybe they wanted +Inf? */
127  if(x > o_threshold) return INFINITY; /* overflow */
128  #endif
129 
130  if(x < u_threshold) return twom1000*twom1000; /* underflow */
131  }
132 
133  /* argument reduction */
134  if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
135  if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
136  hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
137  } else {
138  k = (int32_t) (invln2*x+halF[xsb]);
139  t = k;
140  hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
141  lo = t*ln2LO[0];
142  }
143  x = hi - lo;
144  }
145  else if(hx < 0x3e300000) { /* when |x|<2**-28 */
146  if(huge+x>one) return one+x;/* trigger inexact */
147  }
148  else k = 0;
149 
150  /* x is now in primary range */
151  t = x*x;
152  c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
153  if(k==0) return one-((x*c)/(c-2.0)-x);
154  else y = one-((lo-(x*c)/(2.0-c))-hi);
155  if(k >= -1021) {
156  u_int32_t hy;
157  GET_HIGH_WORD(hy,y);
158  SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */
159  return y;
160  } else {
161  u_int32_t hy;
162  GET_HIGH_WORD(hy,y);
163  SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */
164  return y*twom1000;
165  }
166 }

References GET_HIGH_WORD, GET_LOW_WORD, halF, huge, invln2, k, ln2HI, ln2LO, o_threshold, one, P1, P2, P3, P4, P5, SET_HIGH_WORD, twom1000, and u_threshold.

Variable Documentation

◆ halF

const double halF[2] = {0.5,-0.5,}
static

Definition at line 84 of file e_exp.c.

Referenced by __ieee754_exp().

◆ huge

const double huge = 1.0e+300
static

Definition at line 85 of file e_exp.c.

Referenced by __ieee754_exp().

◆ invln2

const double invln2 = 1.44269504088896338700e+00
static

Definition at line 93 of file e_exp.c.

Referenced by __ieee754_exp().

◆ ln2HI

const double ln2HI[2]
static
Initial value:
={ 6.93147180369123816490e-01,
-6.93147180369123816490e-01,}

Definition at line 89 of file e_exp.c.

Referenced by __ieee754_exp().

◆ ln2LO

const double ln2LO[2]
static
Initial value:
={ 1.90821492927058770002e-10,
-1.90821492927058770002e-10,}

Definition at line 91 of file e_exp.c.

Referenced by __ieee754_exp().

◆ o_threshold

const double o_threshold = 7.09782712893383973096e+02
static

Definition at line 87 of file e_exp.c.

Referenced by __ieee754_exp().

◆ one

const double one = 1.0
static

Definition at line 83 of file e_exp.c.

Referenced by __ieee754_exp().

◆ P1

const double P1 = 1.66666666666666019037e-01
static

Definition at line 94 of file e_exp.c.

Referenced by __ieee754_exp().

◆ P2

const double P2 = -2.77777777770155933842e-03
static

Definition at line 95 of file e_exp.c.

Referenced by __ieee754_exp().

◆ P3

const double P3 = 6.61375632143793436117e-05
static

Definition at line 96 of file e_exp.c.

Referenced by __ieee754_exp().

◆ P4

const double P4 = -1.65339022054652515390e-06
static

Definition at line 97 of file e_exp.c.

Referenced by __ieee754_exp().

◆ P5

const double P5 = 4.13813679705723846039e-08
static

Definition at line 98 of file e_exp.c.

Referenced by __ieee754_exp().

◆ twom1000

const double twom1000 = 9.33263618503218878990e-302
static

Definition at line 86 of file e_exp.c.

Referenced by __ieee754_exp().

◆ u_threshold

const double u_threshold = -7.45133219101941108420e+02
static

Definition at line 88 of file e_exp.c.

Referenced by __ieee754_exp().

P2
static const double P2
Definition: e_exp.c:95
c
const GLubyte * c
Definition: SDL_opengl_glext.h:11096
P4
static const double P4
Definition: e_exp.c:97
huge
static const double huge
Definition: e_exp.c:85
o_threshold
static const double o_threshold
Definition: e_exp.c:87
SET_HIGH_WORD
#define SET_HIGH_WORD(d, v)
Definition: math_private.h:137
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
u_threshold
static const double u_threshold
Definition: e_exp.c:88
int32_t
signed int int32_t
Definition: SDL_config_windows.h:62
u_int32_t
unsigned int u_int32_t
Definition: math_private.h:31
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
ln2HI
static const double ln2HI[2]
Definition: e_exp.c:89
P1
static const double P1
Definition: e_exp.c:94
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
twom1000
static const double twom1000
Definition: e_exp.c:86
P5
static const double P5
Definition: e_exp.c:98
k
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int return Display return Display Cursor return Display GC return XModifierKeymap return char Display Window int return Display return Display int int int return Display long XVisualInfo int return Display Window Atom long long Bool Atom Atom int unsigned long unsigned long k)
Definition: SDL_x11sym.h:80
P3
static const double P3
Definition: e_exp.c:96
GET_LOW_WORD
#define GET_LOW_WORD(i, d)
Definition: math_private.h:118
invln2
static const double invln2
Definition: e_exp.c:93
halF
static const double halF[2]
Definition: e_exp.c:84
ln2LO
static const double ln2LO[2]
Definition: e_exp.c:91
GET_HIGH_WORD
#define GET_HIGH_WORD(i, d)
Definition: math_private.h:109
one
static const double one
Definition: e_exp.c:83