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.

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().

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 }
#define GET_HIGH_WORD(i, d)
Definition: math_private.h:109
static const double twom1000
Definition: e_exp.c:86
static const double P5
Definition: e_exp.c:98
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
signed int int32_t
static const double ln2HI[2]
Definition: e_exp.c:89
static const double one
Definition: e_exp.c:83
#define SET_HIGH_WORD(d, v)
Definition: math_private.h:137
static const double P4
Definition: e_exp.c:97
unsigned int u_int32_t
Definition: math_private.h:31
static const double halF[2]
Definition: e_exp.c:84
static const double P3
Definition: e_exp.c:96
static const double invln2
Definition: e_exp.c:93
static const double ln2LO[2]
Definition: e_exp.c:91
const GLubyte * c
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
static const double u_threshold
Definition: e_exp.c:88
#define GET_LOW_WORD(i, d)
Definition: math_private.h:118
static const double P2
Definition: e_exp.c:95
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:85
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
static const double P1
Definition: e_exp.c:94
static const double o_threshold
Definition: e_exp.c:87

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(), and SDL_Convert_F32_to_S32_Scalar().

◆ 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().