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 96 of file e_exp.c.

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

Referenced by __ieee754_exp().

97 {
98  double y;
99  double hi = 0.0;
100  double lo = 0.0;
101  double c;
102  double t;
103  int32_t k=0;
104  int32_t xsb;
105  u_int32_t hx;
106 
107  GET_HIGH_WORD(hx,x);
108  xsb = (hx>>31)&1; /* sign bit of x */
109  hx &= 0x7fffffff; /* high word of |x| */
110 
111  /* filter out non-finite argument */
112  if(hx >= 0x40862E42) { /* if |x|>=709.78... */
113  if(hx>=0x7ff00000) {
114  u_int32_t lx;
115  GET_LOW_WORD(lx,x);
116  if(((hx&0xfffff)|lx)!=0)
117  return x+x; /* NaN */
118  else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
119  }
120  #if 1
121  if(x > o_threshold) return huge*huge; /* overflow */
122  #else /* !!! FIXME: check this: "huge * huge" is a compiler warning, maybe they wanted +Inf? */
123  if(x > o_threshold) return INFINITY; /* overflow */
124  #endif
125 
126  if(x < u_threshold) return twom1000*twom1000; /* underflow */
127  }
128 
129  /* argument reduction */
130  if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
131  if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
132  hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
133  } else {
134  k = (int32_t) (invln2*x+halF[xsb]);
135  t = k;
136  hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
137  lo = t*ln2LO[0];
138  }
139  x = hi - lo;
140  }
141  else if(hx < 0x3e300000) { /* when |x|<2**-28 */
142  if(huge+x>one) return one+x;/* trigger inexact */
143  }
144  else k = 0;
145 
146  /* x is now in primary range */
147  t = x*x;
148  c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
149  if(k==0) return one-((x*c)/(c-2.0)-x);
150  else y = one-((lo-(x*c)/(2.0-c))-hi);
151  if(k >= -1021) {
152  u_int32_t hy;
153  GET_HIGH_WORD(hy,y);
154  SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */
155  return y;
156  } else {
157  u_int32_t hy;
158  GET_HIGH_WORD(hy,y);
159  SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */
160  return y*twom1000;
161  }
162 }
#define GET_HIGH_WORD(i, d)
Definition: math_private.h:109
static const double twom1000
Definition: e_exp.c:82
static const double P5
Definition: e_exp.c:94
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
signed int int32_t
static const double ln2HI[2]
Definition: e_exp.c:85
static const double one
Definition: e_exp.c:79
#define SET_HIGH_WORD(d, v)
Definition: math_private.h:137
static const double P4
Definition: e_exp.c:93
unsigned int u_int32_t
Definition: math_private.h:31
static const double halF[2]
Definition: e_exp.c:80
static const double P3
Definition: e_exp.c:92
static const double invln2
Definition: e_exp.c:89
static const double ln2LO[2]
Definition: e_exp.c:87
const GLubyte * c
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
static const double u_threshold
Definition: e_exp.c:84
#define GET_LOW_WORD(i, d)
Definition: math_private.h:118
static const double P2
Definition: e_exp.c:91
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 Atom return Display Window XWindowAttributes return Display Window return Display XEvent Bool(*) XPointer return Display Window Bool unsigned int int int Window Cursor Time return Display Window int return KeySym return Display _Xconst char Bool return Display _Xconst char return XKeyEvent char int KeySym XComposeStatus return Display int int int XVisualInfo return Display Window int int return _Xconst char return Display XEvent return Display Drawable GC XImage int int int int unsigned int unsigned int return Display Window Window Window int int int int unsigned int return Display Window Window int int return Display Window unsigned int unsigned int return Display Window Bool long XEvent return Display GC unsigned long return Display Window int Time return Display Window Window return Display Window unsigned long return Display Window XSizeHints Display Colormap XColor int return char int XTextProperty return XFontStruct _Xconst char int int int int XCharStruct return Display Window return Display Time return Display Colormap return Display Window Window int int unsigned int unsigned int int int return Display Window int return XExtensionInfo Display char XExtensionHooks int XPointer return XExtensionInfo XExtensionInfo Display return Display return Display unsigned long Display GC Display char long Display xReply int Bool return Display Bool return Display int SDL_X11_XESetEventToWireRetType return Display Window Window Window Window unsigned int return Display XShmSegmentInfo return Display Drawable GC XImage int int int int unsigned int unsigned int Boo k)
Definition: SDL_x11sym.h:213
static const double huge
Definition: e_exp.c:81
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
static const double P1
Definition: e_exp.c:90
static const double o_threshold
Definition: e_exp.c:83

Variable Documentation

§ halF

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

Definition at line 80 of file e_exp.c.

Referenced by __ieee754_exp().

§ huge

const double huge = 1.0e+300
static

Definition at line 81 of file e_exp.c.

Referenced by __ieee754_exp().

§ invln2

const double invln2 = 1.44269504088896338700e+00
static

Definition at line 89 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 85 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 87 of file e_exp.c.

Referenced by __ieee754_exp().

§ o_threshold

const double o_threshold = 7.09782712893383973096e+02
static

Definition at line 83 of file e_exp.c.

Referenced by __ieee754_exp().

§ one

const double one = 1.0
static

Definition at line 79 of file e_exp.c.

Referenced by __ieee754_exp(), and SDL_Convert_F32_to_S32_Scalar().

§ P1

const double P1 = 1.66666666666666019037e-01
static

Definition at line 90 of file e_exp.c.

Referenced by __ieee754_exp().

§ P2

const double P2 = -2.77777777770155933842e-03
static

Definition at line 91 of file e_exp.c.

Referenced by __ieee754_exp().

§ P3

const double P3 = 6.61375632143793436117e-05
static

Definition at line 92 of file e_exp.c.

Referenced by __ieee754_exp().

§ P4

const double P4 = -1.65339022054652515390e-06
static

Definition at line 93 of file e_exp.c.

Referenced by __ieee754_exp().

§ P5

const double P5 = 4.13813679705723846039e-08
static

Definition at line 94 of file e_exp.c.

Referenced by __ieee754_exp().

§ twom1000

const double twom1000 = 9.33263618503218878990e-302
static

Definition at line 82 of file e_exp.c.

Referenced by __ieee754_exp().

§ u_threshold

const double u_threshold = -7.45133219101941108420e+02
static

Definition at line 84 of file e_exp.c.

Referenced by __ieee754_exp().