ReactOS 0.4.15-dev-7907-g95bf896
remainder_piby2f.c File Reference
#include "libm.h"
#include "libm_util.h"
Include dependency graph for remainder_piby2f.c:

Go to the source code of this file.

Macros

#define bitsper   36
 

Functions

void __remainder_piby2f (unsigned long long ux, double *r, int *region)
 

Macro Definition Documentation

◆ bitsper

#define bitsper   36

Function Documentation

◆ __remainder_piby2f()

void __remainder_piby2f ( unsigned long long  ux,
double r,
int region 
)

Definition at line 35 of file remainder_piby2f.c.

36{
37
38
39 /* This method simulates multi-precision floating-point
40 arithmetic and is accurate for all 1 <= x < infinity */
41#define bitsper 36
42 unsigned long long res[10];
43 unsigned long long u, carry, mask, mant, nextbits;
44 int first, last, i, rexp, xexp, resexp, ltb, determ, bc;
45 double dx;
46 static const double
47 piby2 = 1.57079632679489655800e+00; /* 0x3ff921fb54442d18 */
48 static unsigned long long pibits[] =
49 {
50 0LL,
51 5215LL, 13000023176LL, 11362338026LL, 67174558139LL,
52 34819822259LL, 10612056195LL, 67816420731LL, 57840157550LL,
53 19558516809LL, 50025467026LL, 25186875954LL, 18152700886LL
54 };
55
56
57 xexp = (int)(((ux & EXPBITS_DP64) >> EXPSHIFTBITS_DP64) - EXPBIAS_DP64);
58 ux = ((ux & MANTBITS_DP64) | IMPBIT_DP64) >> 29;
59
60
61 /* Now ux is the mantissa bit pattern of x as a long integer */
62 mask = 1;
63 mask = (mask << bitsper) - 1;
64
65 /* Set first and last to the positions of the first
66 and last chunks of 2/pi that we need */
67 first = xexp / bitsper;
68 resexp = xexp - first * bitsper;
69 /* 120 is the theoretical maximum number of bits (actually
70 115 for IEEE single precision) that we need to extract
71 from the middle of 2/pi to compute the reduced argument
72 accurately enough for our purposes */
73 last = first + 120 / bitsper;
74
75
76 /* Do a long multiplication of the bits of 2/pi by the
77 integer mantissa */
78#if 0
79 for (i = last; i >= first; i--)
80 {
81 u = pibits[i] * ux + carry;
82 res[i - first] = u & mask;
83 carry = u >> bitsper;
84 }
85 res[last - first + 1] = 0;
86#else
87 /* Unroll the loop. This is only correct because we know
88 that bitsper is fixed as 36. */
89 res[4] = 0;
90 u = pibits[last] * ux;
91 res[3] = u & mask;
92 carry = u >> bitsper;
93 u = pibits[last - 1] * ux + carry;
94 res[2] = u & mask;
95 carry = u >> bitsper;
96 u = pibits[last - 2] * ux + carry;
97 res[1] = u & mask;
98 carry = u >> bitsper;
99 u = pibits[first] * ux + carry;
100 res[0] = u & mask;
101#endif
102
103
104 /* Reconstruct the result */
105 ltb = (int)((((res[0] << bitsper) | res[1])
106 >> (bitsper - 1 - resexp)) & 7);
107
108 /* determ says whether the fractional part is >= 0.5 */
109 determ = ltb & 1;
110
111 i = 1;
112 if (determ)
113 {
114 /* The mantissa is >= 0.5. We want to subtract it
115 from 1.0 by negating all the bits */
116 *region = ((ltb >> 1) + 1) & 3;
117 mant = 1;
118 mant = ~(res[1]) & ((mant << (bitsper - resexp)) - 1);
119 while (mant < 0x0000000000010000)
120 {
121 i++;
122 mant = (mant << bitsper) | (~(res[i]) & mask);
123 }
124 nextbits = (~(res[i+1]) & mask);
125 }
126 else
127 {
128 *region = (ltb >> 1);
129 mant = 1;
130 mant = res[1] & ((mant << (bitsper - resexp)) - 1);
131 while (mant < 0x0000000000010000)
132 {
133 i++;
134 mant = (mant << bitsper) | res[i];
135 }
136 nextbits = res[i+1];
137 }
138
139
140 /* Normalize the mantissa. The shift value 6 here, determined by
141 trial and error, seems to give optimal speed. */
142 bc = 0;
143 while (mant < 0x0000400000000000)
144 {
145 bc += 6;
146 mant <<= 6;
147 }
148 while (mant < 0x0010000000000000)
149 {
150 bc++;
151 mant <<= 1;
152 }
153 mant |= nextbits >> (bitsper - bc);
154
155 rexp = 52 + resexp - bc - i * bitsper;
156
157
158 /* Put the result exponent rexp onto the mantissa pattern */
159 u = ((unsigned long long)rexp + EXPBIAS_DP64) << EXPSHIFTBITS_DP64;
160 ux = (mant & MANTBITS_DP64) | u;
161 if (determ)
162 /* If we negated the mantissa we negate x too */
163 ux |= SIGNBIT_DP64;
164 PUT_BITS_DP64(ux, dx);
165
166
167 /* x is a double precision version of the fractional part of
168 x * 2 / pi. Multiply x by pi/2 in double precision
169 to get the reduced argument r. */
170 *r = dx * piby2;
171 return;
172
173}
PBATCH_CONTEXT bc
Definition: batch.c:67
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint res
Definition: glext.h:9613
GLenum GLint GLuint mask
Definition: glext.h:6028
const GLint * first
Definition: glext.h:5794
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 IMPBIT_DP64
Definition: libm_util.h:50
#define EXPSHIFTBITS_DP64
Definition: libm_util.h:56
#define SIGNBIT_DP64
Definition: libm_util.h:44
#define EXPBITS_DP64
Definition: libm_util.h:45
#define EXPBIAS_DP64
Definition: libm_util.h:55
#define MANTBITS_DP64
Definition: libm_util.h:46
#define PUT_BITS_DP64(ux, x)
Definition: libm_util.h:124
GLint dx
Definition: linetemp.h:97
static UINT UINT last
Definition: font.c:45
#define long
Definition: qsort.c:33
#define bitsper
#define LL
Definition: tui.h:167