ReactOS 0.4.17-dev-1321-g5c122a9
__rem_pio2.c File Reference
#include "libm.h"
Include dependency graph for __rem_pio2.c:

Go to the source code of this file.

Macros

#define EPS   DBL_EPSILON
 

Functions

int __rem_pio2 (double x, double *y)
 

Variables

static const double toint = 1.5/EPS
 
static const double pio4 = 0x1.921fb54442d18p-1
 
static const double invpio2 = 6.36619772367581382433e-01
 
static const double pio2_1 = 1.57079632673412561417e+00
 
static const double pio2_1t = 6.07710050650619224932e-11
 
static const double pio2_2 = 6.07710050630396597660e-11
 
static const double pio2_2t = 2.02226624879595063154e-21
 
static const double pio2_3 = 2.02226624871116645580e-21
 
static const double pio2_3t = 8.47842766036889956997e-32
 

Macro Definition Documentation

◆ EPS

#define EPS   DBL_EPSILON

Definition at line 33 of file __rem_pio2.c.

Function Documentation

◆ __rem_pio2()

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
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
GLdouble n
Definition: glext.h:7729
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
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
#define sign(x)
Definition: mapdesc.cc:613
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().

Variable Documentation

◆ invpio2

const double invpio2 = 6.36619772367581382433e-01
static

Definition at line 50 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ pio2_1

const double pio2_1 = 1.57079632673412561417e+00
static

Definition at line 51 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ pio2_1t

const double pio2_1t = 6.07710050650619224932e-11
static

Definition at line 52 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ pio2_2

const double pio2_2 = 6.07710050630396597660e-11
static

Definition at line 53 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ pio2_2t

const double pio2_2t = 2.02226624879595063154e-21
static

Definition at line 54 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ pio2_3

const double pio2_3 = 2.02226624871116645580e-21
static

Definition at line 55 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ pio2_3t

const double pio2_3t = 8.47842766036889956997e-32
static

Definition at line 56 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ pio4

const double pio4 = 0x1.921fb54442d18p-1
static

Definition at line 49 of file __rem_pio2.c.

Referenced by __rem_pio2().

◆ toint

const double toint = 1.5/EPS
static

Definition at line 48 of file __rem_pio2.c.

Referenced by __rem_pio2().