ReactOS 0.4.17-dev-1321-g5c122a9
libm.h File Reference
#include <stdint.h>
#include <float.h>
#include <math.h>
Include dependency graph for libm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _STATIC_ASSERT(expr)   extern char (*__static_assert__(void)) [(expr) ? 1 : -1]
 
#define isnan   _isnan
 
#define isnanf   _isnanf
 
#define signbit(x)
 
#define FORCE_EVAL(x)
 
#define hidden
 
#define WANT_ROUNDING   1
 
#define WANT_SNAN   0
 
#define issignalingf_inline(x)   0
 
#define issignaling_inline(x)   0
 
#define TOINT_INTRINSICS   0
 
#define predict_true(x)   (x)
 
#define predict_false(x)   (x)
 
#define EXTRACT_WORDS(hi, lo, d)
 
#define GET_HIGH_WORD(hi, d)
 
#define GET_LOW_WORD(lo, d)
 
#define INSERT_WORDS(d, hi, lo)
 
#define SET_HIGH_WORD(d, hi)    INSERT_WORDS(d, hi, (uint32_t)asuint64(d))
 
#define SET_LOW_WORD(d, lo)    INSERT_WORDS(d, asuint64(d)>>32, lo)
 
#define GET_FLOAT_WORD(w, d)
 
#define SET_FLOAT_WORD(d, w)
 
#define FP_ILOGB0   (-0x7fffffff - 1)
 
#define FP_ILOGBNAN   0x7fffffff
 
#define isfinite(x)   (_finite((double)(x)) != 0)
 

Functions

 _STATIC_ASSERT (sizeof(float)==4)
 
 _STATIC_ASSERT (sizeof(double)==8)
 
 _STATIC_ASSERT (sizeof(long double)==8)
 
_Check_return_ int __cdecl _isnanf (_In_ float _X)
 
static __inline uint32_t __FLOAT_BITS (float __f)
 
static __inline uint64_t __DOUBLE_BITS (double __f)
 
static void fp_force_evalf (float x)
 
static void fp_force_eval (double x)
 
static float eval_as_float (float x)
 
static double eval_as_double (double x)
 
static float fp_barrierf (float x)
 
static double fp_barrier (double x)
 
static uint32_t asuint (float f)
 
static float asfloat (uint32_t i)
 
static uint64_t asuint64 (double f)
 
static double asdouble (uint64_t i)
 
_Check_return_ int __cdecl _finite (_In_ double _X)
 
int ilogb (double)
 
double logb (double)
 
double scalbn (double, int)
 
hidden int __rem_pio2_large (double *, double *, int, int, int)
 
hidden int __rem_pio2 (double, double *)
 
hidden double __tan (double, double, int)
 
hidden double __math_xflow (uint32_t, double)
 
hidden double __math_uflow (uint32_t)
 
hidden double __math_oflow (uint32_t)
 
hidden double __math_divzero (uint32_t)
 
hidden double __math_invalid (double)
 

Macro Definition Documentation

◆ _STATIC_ASSERT

#define _STATIC_ASSERT (   expr)    extern char (*__static_assert__(void)) [(expr) ? 1 : -1]

Definition at line 19 of file libm.h.

◆ EXTRACT_WORDS

#define EXTRACT_WORDS (   hi,
  lo,
  d 
)
Value:
do { \
uint64_t __u = asuint64(d); \
(hi) = __u >> 32; \
(lo) = (uint32_t)__u; \
} while (0)
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
#define d
Definition: ke_i.h:81
static uint64_t asuint64(double f)
Definition: libm.h:135

Definition at line 149 of file libm.h.

◆ FORCE_EVAL

#define FORCE_EVAL (   x)
Value:
do { \
if (sizeof(x) == sizeof(float)) { \
fp_force_evalf(x); \
} else { \
fp_force_eval(x); \
} \
} while(0)
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Definition at line 64 of file libm.h.

◆ FP_ILOGB0

#define FP_ILOGB0   (-0x7fffffff - 1)

Definition at line 188 of file libm.h.

◆ FP_ILOGBNAN

#define FP_ILOGBNAN   0x7fffffff

Definition at line 191 of file libm.h.

◆ GET_FLOAT_WORD

#define GET_FLOAT_WORD (   w,
  d 
)
Value:
do { \
(w) = asuint(d); \
} while (0)
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
static uint32_t asuint(float f)
Definition: libm.h:121

Definition at line 177 of file libm.h.

◆ GET_HIGH_WORD

#define GET_HIGH_WORD (   hi,
  d 
)
Value:
do { \
(hi) = asuint64(d) >> 32; \
} while (0)

Definition at line 156 of file libm.h.

◆ GET_LOW_WORD

#define GET_LOW_WORD (   lo,
  d 
)
Value:
do { \
(lo) = (uint32_t)asuint64(d); \
} while (0)

Definition at line 161 of file libm.h.

◆ hidden

uint32_t hidden

Definition at line 73 of file libm.h.

Referenced by ewmh_get_window_state(), fsctl_set_xattr(), id(), TOOLBAR_SetRows(), and ui_seamless_begin().

◆ INSERT_WORDS

#define INSERT_WORDS (   d,
  hi,
  lo 
)
Value:
do { \
(d) = asdouble(((uint64_t)(hi)<<32) | (uint32_t)(lo)); \
} while (0)
static double asdouble(uint64_t i)
Definition: libm.h:142
#define uint32_t
Definition: nsiface.idl:61

Definition at line 166 of file libm.h.

◆ isfinite

#define isfinite (   x)    (_finite((double)(x)) != 0)

Definition at line 197 of file libm.h.

◆ isnan

#define isnan   _isnan

Definition at line 28 of file libm.h.

◆ isnanf

#define isnanf   _isnanf

Definition at line 29 of file libm.h.

◆ issignaling_inline

#define issignaling_inline (   x)    0

Definition at line 81 of file libm.h.

◆ issignalingf_inline

#define issignalingf_inline (   x)    0

Definition at line 80 of file libm.h.

◆ predict_false

#define predict_false (   x)    (x)

Definition at line 93 of file libm.h.

◆ predict_true

#define predict_true (   x)    (x)

Definition at line 92 of file libm.h.

◆ SET_FLOAT_WORD

#define SET_FLOAT_WORD (   d,
  w 
)
Value:
do { \
(d) = asfloat(w); \
} while (0)
static float asfloat(uint32_t i)
Definition: libm.h:128

Definition at line 182 of file libm.h.

◆ SET_HIGH_WORD

#define SET_HIGH_WORD (   d,
  hi 
)     INSERT_WORDS(d, hi, (uint32_t)asuint64(d))

Definition at line 171 of file libm.h.

◆ SET_LOW_WORD

#define SET_LOW_WORD (   d,
  lo 
)     INSERT_WORDS(d, asuint64(d)>>32, lo)

Definition at line 174 of file libm.h.

◆ signbit

#define signbit (   x)
Value:
((sizeof(x) == sizeof(float)) ? (int)(__FLOAT_BITS(x)>>31) : \
(int)(__DOUBLE_BITS(x)>>63))
static __inline uint64_t __DOUBLE_BITS(double __f)
Definition: libm.h:39
static __inline uint32_t __FLOAT_BITS(float __f)
Definition: libm.h:32

Definition at line 46 of file libm.h.

◆ TOINT_INTRINSICS

#define TOINT_INTRINSICS   0

Definition at line 84 of file libm.h.

◆ WANT_ROUNDING

#define WANT_ROUNDING   1

Definition at line 76 of file libm.h.

◆ WANT_SNAN

#define WANT_SNAN   0

Definition at line 78 of file libm.h.

Function Documentation

◆ __DOUBLE_BITS()

static __inline uint64_t __DOUBLE_BITS ( double  __f)
static

Definition at line 39 of file libm.h.

40{
41 union {double __f; uint64_t __i;} __u;
42 __u.__f = __f;
43 return __u.__i;
44}
float __f
Definition: math.h:270
unsigned int __i
Definition: math.h:269

◆ __FLOAT_BITS()

static __inline uint32_t __FLOAT_BITS ( float  __f)
static

Definition at line 32 of file libm.h.

33{
34 union {float __f; uint32_t __i;} __u;
35 __u.__f = __f;
36 return __u.__i;
37}

◆ __math_divzero()

hidden double __math_divzero ( uint32_t  sign)

Definition at line 13 of file __math_divzero.c.

14{
15 return fp_barrier(sign ? -1.0 : 1.0) / 0.0;
16}
static double fp_barrier(double x)
Definition: libm.h:114
#define sign(x)
Definition: mapdesc.cc:613

Referenced by log().

◆ __math_invalid()

hidden double __math_invalid ( double  x)

Definition at line 13 of file __math_invalid.c.

14{
15 return (x - x) / (x - x);
16}

Referenced by log(), pow(), and sqrt().

◆ __math_oflow()

hidden double __math_oflow ( uint32_t  sign)

Definition at line 13 of file __math_oflow.c.

14{
15 return __math_xflow(sign, 0x1p769);
16}
double __math_xflow(uint32_t sign, double y)
Definition: __math_xflow.c:13

Referenced by exp(), exp_inline(), and pow().

◆ __math_uflow()

hidden double __math_uflow ( uint32_t  sign)

Definition at line 13 of file __math_uflow.c.

14{
15 return __math_xflow(sign, 0x1p-767);
16}

Referenced by exp(), exp_inline(), and pow().

◆ __math_xflow()

hidden double __math_xflow ( uint32_t  sign,
double  y 
)

Definition at line 13 of file __math_xflow.c.

14{
15 return eval_as_double(fp_barrier(sign ? -y : y) * y);
16}
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
static double eval_as_double(double x)
Definition: libm.h:102

Referenced by __math_oflow(), and __math_uflow().

◆ __rem_pio2()

hidden int __rem_pio2 ( double  x,
double *  y 
)

Definition at line 59 of file __rem_pio2.c.

60{
61 union {double f; uint64_t i;} u = {x};
62 double_t z,w,t,r,fn;
63 double tx[3],ty[2];
64 uint32_t ix;
65 int sign, n, ex, ey, i;
66
67 sign = u.i>>63;
68 ix = u.i>>32 & 0x7fffffff;
69 if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */
70 if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */
71 goto medium; /* cancellation -- use medium case */
72 if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
73 if (!sign) {
74 z = x - pio2_1; /* one round good to 85 bits */
75 y[0] = z - pio2_1t;
76 y[1] = (z-y[0]) - pio2_1t;
77 return 1;
78 } else {
79 z = x + pio2_1;
80 y[0] = z + pio2_1t;
81 y[1] = (z-y[0]) + pio2_1t;
82 return -1;
83 }
84 } else {
85 if (!sign) {
86 z = x - 2*pio2_1;
87 y[0] = z - 2*pio2_1t;
88 y[1] = (z-y[0]) - 2*pio2_1t;
89 return 2;
90 } else {
91 z = x + 2*pio2_1;
92 y[0] = z + 2*pio2_1t;
93 y[1] = (z-y[0]) + 2*pio2_1t;
94 return -2;
95 }
96 }
97 }
98 if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */
99 if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
100 if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */
101 goto medium;
102 if (!sign) {
103 z = x - 3*pio2_1;
104 y[0] = z - 3*pio2_1t;
105 y[1] = (z-y[0]) - 3*pio2_1t;
106 return 3;
107 } else {
108 z = x + 3*pio2_1;
109 y[0] = z + 3*pio2_1t;
110 y[1] = (z-y[0]) + 3*pio2_1t;
111 return -3;
112 }
113 } else {
114 if (ix == 0x401921fb) /* |x| ~= 4pi/2 */
115 goto medium;
116 if (!sign) {
117 z = x - 4*pio2_1;
118 y[0] = z - 4*pio2_1t;
119 y[1] = (z-y[0]) - 4*pio2_1t;
120 return 4;
121 } else {
122 z = x + 4*pio2_1;
123 y[0] = z + 4*pio2_1t;
124 y[1] = (z-y[0]) + 4*pio2_1t;
125 return -4;
126 }
127 }
128 }
129 if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
130medium:
131 /* rint(x/(pi/2)) */
133 n = (int32_t)fn;
134 r = x - fn*pio2_1;
135 w = fn*pio2_1t; /* 1st round, good to 85 bits */
136 /* Matters with directed rounding. */
137 if (predict_false(r - w < -pio4)) {
138 n--;
139 fn--;
140 r = x - fn*pio2_1;
141 w = fn*pio2_1t;
142 } else if (predict_false(r - w > pio4)) {
143 n++;
144 fn++;
145 r = x - fn*pio2_1;
146 w = fn*pio2_1t;
147 }
148 y[0] = r - w;
149 u.f = y[0];
150 ey = u.i>>52 & 0x7ff;
151 ex = ix>>20;
152 if (ex - ey > 16) { /* 2nd round, good to 118 bits */
153 t = r;
154 w = fn*pio2_2;
155 r = t - w;
156 w = fn*pio2_2t - ((t-r)-w);
157 y[0] = r - w;
158 u.f = y[0];
159 ey = u.i>>52 & 0x7ff;
160 if (ex - ey > 49) { /* 3rd round, good to 151 bits, covers all cases */
161 t = r;
162 w = fn*pio2_3;
163 r = t - w;
164 w = fn*pio2_3t - ((t-r)-w);
165 y[0] = r - w;
166 }
167 }
168 y[1] = (r - y[0]) - w;
169 return n;
170 }
171 /*
172 * all other (large) arguments
173 */
174 if (ix >= 0x7ff00000) { /* x is inf or NaN */
175 y[0] = y[1] = x - x;
176 return 0;
177 }
178 /* set z = scalbn(|x|,-ilogb(x)+23) */
179 u.f = x;
180 u.i &= (uint64_t)-1>>12;
181 u.i |= (uint64_t)(0x3ff + 23)<<52;
182 z = u.f;
183 for (i=0; i < 2; i++) {
184 tx[i] = (double)(int32_t)z;
185 z = (z-tx[i])*0x1p24;
186 }
187 tx[i] = z;
188 /* skip zero terms, first term is non-zero */
189 while (tx[i] == 0.0)
190 i--;
191 n = __rem_pio2_large(tx,ty,(int)(ix>>20)-(0x3ff+23),i+1,1);
192 if (sign) {
193 y[0] = -ty[0];
194 y[1] = -ty[1];
195 return -n;
196 }
197 y[0] = ty[0];
198 y[1] = ty[1];
199 return n;
200}
static const double invpio2
Definition: __rem_pio2.c:50
static const double pio2_1t
Definition: __rem_pio2.c:52
static const double pio2_2t
Definition: __rem_pio2.c:54
static const double pio4
Definition: __rem_pio2.c:49
static const double pio2_3t
Definition: __rem_pio2.c:56
static const double toint
Definition: __rem_pio2.c:48
static const double pio2_1
Definition: __rem_pio2.c:51
static const double pio2_3
Definition: __rem_pio2.c:55
static const double pio2_2
Definition: __rem_pio2.c:53
int __rem_pio2_large(double *x, double *y, int e0, int nx, int prec)
INT32 int32_t
Definition: types.h:71
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
GLdouble n
Definition: glext.h:7729
GLbyte ty
Definition: glext.h:8756
GLdouble GLdouble z
Definition: glext.h:5874
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define f
Definition: ke_i.h:83
#define predict_false(x)
Definition: libm.h:93
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:91
#define uint64_t
Definition: nsiface.idl:62
#define int32_t
Definition: nsiface.idl:56
Definition: comerr.c:44
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Referenced by tan().

◆ __rem_pio2_large()

hidden int __rem_pio2_large ( double *  x,
double *  y,
int  e0,
int  nx,
int  prec 
)

Definition at line 283 of file __rem_pio2_large.c.

284{
285 int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
286 double z,fw,f[20],fq[20],q[20];
287
288 /* initialize jk*/
289 jk = init_jk[prec];
290 jp = jk;
291
292 /* determine jx,jv,q0, note that 3>q0 */
293 jx = nx-1;
294 jv = (e0-3)/24; if(jv<0) jv=0;
295 q0 = e0-24*(jv+1);
296
297 /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
298 j = jv-jx; m = jx+jk;
299 for (i=0; i<=m; i++,j++)
300 f[i] = j<0 ? 0.0 : (double)ipio2[j];
301
302 /* compute q[0],q[1],...q[jk] */
303 for (i=0; i<=jk; i++) {
304 for (j=0,fw=0.0; j<=jx; j++)
305 fw += x[j]*f[jx+i-j];
306 q[i] = fw;
307 }
308
309 jz = jk;
310recompute:
311 /* distill q[] into iq[] reversingly */
312 for (i=0,j=jz,z=q[jz]; j>0; i++,j--) {
313 fw = (double)(int32_t)(0x1p-24*z);
314 iq[i] = (int32_t)(z - 0x1p24*fw);
315 z = q[j-1]+fw;
316 }
317
318 /* compute n */
319 z = scalbn(z,q0); /* actual value of z */
320 z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
321 n = (int32_t)z;
322 z -= (double)n;
323 ih = 0;
324 if (q0 > 0) { /* need iq[jz-1] to determine n */
325 i = iq[jz-1]>>(24-q0); n += i;
326 iq[jz-1] -= i<<(24-q0);
327 ih = iq[jz-1]>>(23-q0);
328 }
329 else if (q0 == 0) ih = iq[jz-1]>>23;
330 else if (z >= 0.5) ih = 2;
331
332 if (ih > 0) { /* q > 0.5 */
333 n += 1; carry = 0;
334 for (i=0; i<jz; i++) { /* compute 1-q */
335 j = iq[i];
336 if (carry == 0) {
337 if (j != 0) {
338 carry = 1;
339 iq[i] = 0x1000000 - j;
340 }
341 } else
342 iq[i] = 0xffffff - j;
343 }
344 if (q0 > 0) { /* rare case: chance is 1 in 12 */
345 switch(q0) {
346 case 1:
347 iq[jz-1] &= 0x7fffff; break;
348 case 2:
349 iq[jz-1] &= 0x3fffff; break;
350 }
351 }
352 if (ih == 2) {
353 z = 1.0 - z;
354 if (carry != 0)
355 z -= scalbn(1.0,q0);
356 }
357 }
358
359 /* check if recomputation is needed */
360 if (z == 0.0) {
361 j = 0;
362 for (i=jz-1; i>=jk; i--) j |= iq[i];
363 if (j == 0) { /* need recomputation */
364 for (k=1; iq[jk-k]==0; k++); /* k = no. of terms needed */
365
366 for (i=jz+1; i<=jz+k; i++) { /* add q[jz+1] to q[jz+k] */
367 f[jx+i] = (double)ipio2[jv+i];
368 for (j=0,fw=0.0; j<=jx; j++)
369 fw += x[j]*f[jx+i-j];
370 q[i] = fw;
371 }
372 jz += k;
373 goto recompute;
374 }
375 }
376
377 /* chop off zero terms */
378 if (z == 0.0) {
379 jz -= 1;
380 q0 -= 24;
381 while (iq[jz] == 0) {
382 jz--;
383 q0 -= 24;
384 }
385 } else { /* break z into 24-bit if necessary */
386 z = scalbn(z,-q0);
387 if (z >= 0x1p24) {
388 fw = (double)(int32_t)(0x1p-24*z);
389 iq[jz] = (int32_t)(z - 0x1p24*fw);
390 jz += 1;
391 q0 += 24;
392 iq[jz] = (int32_t)fw;
393 } else
394 iq[jz] = (int32_t)z;
395 }
396
397 /* convert integer "bit" chunk to floating-point value */
398 fw = scalbn(1.0,q0);
399 for (i=jz; i>=0; i--) {
400 q[i] = fw*(double)iq[i];
401 fw *= 0x1p-24;
402 }
403
404 /* compute PIo2[0,...,jp]*q[jz,...,0] */
405 for(i=jz; i>=0; i--) {
406 for (fw=0.0,k=0; k<=jp && k<=jz-i; k++)
407 fw += PIo2[k]*q[i+k];
408 fq[jz-i] = fw;
409 }
410
411 /* compress fq[] into y[] */
412 switch(prec) {
413 case 0:
414 fw = 0.0;
415 for (i=jz; i>=0; i--)
416 fw += fq[i];
417 y[0] = ih==0 ? fw : -fw;
418 break;
419 case 1:
420 case 2:
421 fw = 0.0;
422 for (i=jz; i>=0; i--)
423 fw += fq[i];
424 // TODO: drop excess precision here once double_t is used
425 fw = (double)fw;
426 y[0] = ih==0 ? fw : -fw;
427 fw = fq[0]-fw;
428 for (i=1; i<=jz; i++)
429 fw += fq[i];
430 y[1] = ih==0 ? fw : -fw;
431 break;
432 case 3: /* painful */
433 for (i=jz; i>0; i--) {
434 fw = fq[i-1]+fq[i];
435 fq[i] += fq[i-1]-fw;
436 fq[i-1] = fw;
437 }
438 for (i=jz; i>1; i--) {
439 fw = fq[i-1]+fq[i];
440 fq[i] += fq[i-1]-fw;
441 fq[i-1] = fw;
442 }
443 for (fw=0.0,i=jz; i>=2; i--)
444 fw += fq[i];
445 if (ih==0) {
446 y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
447 } else {
448 y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
449 }
450 }
451 return n&7;
452}
static const int32_t ipio2[]
static const double PIo2[]
static const int init_jk[]
_ACRTIMP double __cdecl scalbn(double, int)
Definition: scalbn.c:14
_ACRTIMP double __cdecl floor(double)
Definition: floor.c:18
static const uint32_t k[]
Definition: sha256.c:24
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat f
Definition: glext.h:7540
GLfloat GLfloat GLfloat GLfloat nx
Definition: glext.h:8898
const GLfloat * m
Definition: glext.h:10848
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250

Referenced by __rem_pio2().

◆ __tan()

hidden double __tan ( double  x,
double  y,
int  odd 
)

Definition at line 76 of file __tan.c.

77{
78 double_t z, r, v, w, s, a;
79 double w0, a0;
80 uint32_t hx;
81 int big, sign;
82
83 GET_HIGH_WORD(hx,x);
84 big = (hx&0x7fffffff) >= 0x3FE59428; /* |x| >= 0.6744 */
85 if (big) {
86 sign = hx>>31;
87 if (sign) {
88 x = -x;
89 y = -y;
90 }
91 x = (pio4 - x) + (pio4lo - y);
92 y = 0.0;
93 }
94 z = x * x;
95 w = z * z;
96 /*
97 * Break x^5*(T[1]+x^2*T[2]+...) into
98 * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
99 * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
100 */
101 r = T[1] + w*(T[3] + w*(T[5] + w*(T[7] + w*(T[9] + w*T[11]))));
102 v = z*(T[2] + w*(T[4] + w*(T[6] + w*(T[8] + w*(T[10] + w*T[12])))));
103 s = z * x;
104 r = y + z*(s*(r + v) + y) + s*T[0];
105 w = x + r;
106 if (big) {
107 s = 1 - 2*odd;
108 v = s - 2.0 * (x + (r - w*w/(w + s)));
109 return sign ? -v : v;
110 }
111 if (!odd)
112 return w;
113 /* -1.0/(x+r) has up to 2ulp error, so compute it accurately */
114 w0 = w;
115 SET_LOW_WORD(w0, 0);
116 v = r - (w0 - x); /* w0+v = r+x */
117 a0 = a = -1.0 / w;
118 SET_LOW_WORD(a0, 0);
119 return a0 + a*(1.0 + a0*w0 + a0*v);
120}
static const double T[]
Definition: __tan.c:58
static const double pio4lo
Definition: __tan.c:74
static const double pio4
Definition: __tan.c:73
#define odd(x)
Definition: bidi.c:60
const GLdouble * v
Definition: gl.h:2040
GLdouble s
Definition: gl.h:2039
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define GET_HIGH_WORD(i, d)
Definition: ieee754.h:26
#define a
Definition: ke_i.h:78
#define SET_LOW_WORD(d, lo)
Definition: libm.h:174
Definition: unary.h:11

Referenced by tan().

◆ _finite()

Definition at line 14 of file _finite.c.

15{
16 union { double f; uint64_t ui64; } u = { _X };
17 uint64_t exp = u.ui64 & 0x7FF0000000000000;
18 return (exp != 0x7FF0000000000000);
19}
#define _X(x)
Definition: CPath.cpp:42
DWORD exp
Definition: msg.c:18625

◆ _isnanf()

_Check_return_ int __cdecl _isnanf ( _In_ float  _X)

Definition at line 13 of file _isnanf.c.

14{
15 union { float f; uint32_t ui32; } u = { _X };
16 return (u.ui32 & ~0x80000000) > 0x7F800000;
17}

◆ _STATIC_ASSERT() [1/3]

_STATIC_ASSERT ( sizeof(double)  = =8)

◆ _STATIC_ASSERT() [2/3]

_STATIC_ASSERT ( sizeof(float)  = =4)

◆ _STATIC_ASSERT() [3/3]

_STATIC_ASSERT ( sizeof(long double)  = =8)

◆ asdouble()

static double asdouble ( uint64_t  i)
inlinestatic

Definition at line 142 of file libm.h.

143{
144 union {uint64_t _i; double _f;} u;
145 u._i = i;
146 return u._f;
147}

Referenced by exp(), exp_inline(), log(), log_inline(), pow(), specialcase(), and sqrt().

◆ asfloat()

static float asfloat ( uint32_t  i)
inlinestatic

Definition at line 128 of file libm.h.

129{
130 union {uint32_t _i; float _f;} u;
131 u._i = i;
132 return u._f;
133}

◆ asuint()

static uint32_t asuint ( float  f)
inlinestatic

Definition at line 121 of file libm.h.

122{
123 union {float _f; uint32_t _i;} u;
124 u._f = f;
125 return u._i;
126}

Referenced by _logbf().

◆ asuint64()

static uint64_t asuint64 ( double  f)
inlinestatic

Definition at line 135 of file libm.h.

136{
137 union {double _f; uint64_t _i;} u;
138 u._f = f;
139 return u._i;
140}

Referenced by _logb(), exp(), exp_inline(), log(), pow(), sqrt(), top12(), top16(), and zeroinfnan().

◆ eval_as_double()

static double eval_as_double ( double  x)
inlinestatic

Definition at line 102 of file libm.h.

103{
104 double y = x;
105 return y;
106}

Referenced by __math_xflow(), exp(), exp_inline(), log(), specialcase(), and sqrt().

◆ eval_as_float()

static float eval_as_float ( float  x)
inlinestatic

Definition at line 96 of file libm.h.

97{
98 float y = x;
99 return y;
100}

◆ fp_barrier()

static double fp_barrier ( double  x)
inlinestatic

Definition at line 114 of file libm.h.

115{
116 volatile double y = x;
117 return y;
118}

Referenced by __math_divzero(), __math_xflow(), pow(), and specialcase().

◆ fp_barrierf()

static float fp_barrierf ( float  x)
inlinestatic

Definition at line 108 of file libm.h.

109{
110 volatile float y = x;
111 return y;
112}

Referenced by ilogb().

◆ fp_force_eval()

static void fp_force_eval ( double  x)
inlinestatic

Definition at line 57 of file libm.h.

58{
59 volatile double y;
60 y = x;
61 (void)y;
62}

Referenced by specialcase().

◆ fp_force_evalf()

static void fp_force_evalf ( float  x)
inlinestatic

Definition at line 50 of file libm.h.

51{
52 volatile float y;
53 y = x;
54 (void)y;
55}

◆ ilogb()

int ilogb ( double  x)

Definition at line 14 of file ilogb.c.

15{
16 #pragma STDC FENV_ACCESS ON
17 union {double f; uint64_t i;} u = {x};
18 uint64_t i = u.i;
19 int e = i>>52 & 0x7ff;
20
21 if (!e) {
22 i <<= 12;
23 if (i == 0) {
24 FORCE_EVAL(fp_barrierf(0.0f)/0.0f);
25 return FP_ILOGB0;
26 }
27 /* subnormal x */
28 for (e = -0x3ff; i>>63 == 0; e--, i<<=1);
29 return e;
30 }
31 if (e == 0x7ff) {
32 FORCE_EVAL(fp_barrierf(0.0f)/0.0f);
33 return i<<12 ? FP_ILOGBNAN : INT_MAX;
34 }
35 return e - 0x3ff;
36}
#define INT_MAX
Definition: limits.h:26
#define FP_ILOGBNAN
Definition: math.h:285
#define FP_ILOGB0
Definition: math.h:284
#define e
Definition: ke_i.h:82
#define FORCE_EVAL(x)
Definition: libm.h:64
static float fp_barrierf(float x)
Definition: libm.h:108

◆ logb()

double logb ( double  x)

Definition at line 243 of file mingw_math.h.

244 {
245 double res = 0.0;
246 __asm__ __volatile__ ("fxtract\n\t"
247 "fstp %%st" : "=t" (res) : "0" (x));
248 return res;
249 }
GLuint res
Definition: glext.h:9613
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tpush %rbx\n" "\t.seh_pushreg %rbx\n" "\tpush %rdi\n" "\t.seh_pushreg %rdi\n" "\tpush %rsi\n" "\t.seh_pushreg %rsi\n" "\tpush %r12\n" "\t.seh_pushreg %r12\n" "\tpush %r13\n" "\t.seh_pushreg %r13\n" "\tpush %r14\n" "\t.seh_pushreg %r14\n" "\tpush %r15\n" "\t.seh_pushreg %r15\n" "\tsub $40, %rsp\n" "\t.seh_stackalloc 40\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $40, %rsp\n" "\tpop %r15\n" "\tpop %r14\n" "\tpop %r13\n" "\tpop %r12\n" "\tpop %rsi\n" "\tpop %rdi\n" "\tpop %rbx\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")

◆ scalbn()

double scalbn ( double  x,
int  n 
)

Definition at line 14 of file scalbn.c.

15{
16 union {double f; uint64_t i;} u;
17 double_t y = x;
18
19 if (n > 1023) {
20 y *= 0x1p1023;
21 n -= 1023;
22 if (n > 1023) {
23 y *= 0x1p1023;
24 n -= 1023;
25 if (n > 1023)
26 n = 1023;
27 }
28 } else if (n < -1022) {
29 /* make sure final n < -53 to avoid double
30 rounding in the subnormal range */
31 y *= 0x1p-1022 * 0x1p53;
32 n += 1022 - 53;
33 if (n < -1022) {
34 y *= 0x1p-1022 * 0x1p53;
35 n += 1022 - 53;
36 if (n < -1022)
37 n = -1022;
38 }
39 }
40 u.i = (uint64_t)(0x3ff+n)<<52;
41 x = y * u.f;
42 return x;
43}