2 * Floating Point Interpreter.
3 * shamelessly stolen from an original by ark.
12 guard = i->l & GuardMask;
14 if(guard > (LsBit>>1) || (guard == (LsBit>>1) && (i->l & LsBit))){
31 matchexponents(Internal *x, Internal *y)
37 if(count >= 2*FractBits){
42 if(count >= FractBits){
44 x->l = x->h|(x->l != 0);
71 normalise(Internal *i)
73 while((i->h & HiddenBit) == 0)
78 renormalise(Internal *i)
80 if(i->e < -2 * FractBits)
81 i->e = -2 * FractBits;
87 i->l = (i->l>>1)|(i->l & 0x01);
89 if(i->e >= ExpInfinity)
94 fpinormalise(Internal *x)
96 if(!IsWeird(x) && !IsZero(x))
101 fpiadd(Internal *x, Internal *y, Internal *i)
106 if(IsWeird(x) || IsWeird(y)){
107 if(IsNaN(x) || IsNaN(y))
118 matchexponents(x, y);
126 if(i->h & (HiddenBit<<1)){
129 i->l = (i->l>>1)|(i->l & 0x01);
138 fpisub(Internal *x, Internal *y, Internal *i)
143 || (y->e == x->e && (y->h < x->h || (y->h == x->h && y->l < x->l)))){
160 matchexponents(x, y);
168 if(i->h == 0 && i->l == 0)
170 else while(i->e > 1 && (i->h & HiddenBit) == 0)
174 #define CHUNK (FractBits/2)
175 #define CMASK ((1<<CHUNK)-1)
176 #define HI(x) ((short)((x)>>CHUNK) & CMASK)
177 #define LO(x) ((short)(x) & CMASK)
178 #define SPILL(x) ((x)>>CHUNK)
179 #define M(x, y) ((long)a[x]*(long)b[y])
180 #define C(h, l) (((long)((h) & CMASK)<<CHUNK)|((l) & CMASK))
183 fpimul(Internal *x, Internal *y, Internal *i)
185 long a[4], b[4], c[7], f[4];
188 if(IsWeird(x) || IsWeird(y)){
189 if(IsNaN(x) || IsNaN(y) || IsZero(x) || IsZero(y))
195 else if(IsZero(x) || IsZero(y)){
201 i->e = x->e + y->e - (ExpBias - 1);
203 a[0] = HI(x->h); b[0] = HI(y->h);
204 a[1] = LO(x->h); b[1] = LO(y->h);
205 a[2] = HI(x->l); b[2] = HI(y->l);
206 a[3] = LO(x->l); b[3] = LO(y->l);
209 c[5] = M(2, 3) + M(3, 2) + SPILL(c[6]);
210 c[4] = M(1, 3) + M(2, 2) + M(3, 1) + SPILL(c[5]);
211 c[3] = M(0, 3) + M(1, 2) + M(2, 1) + M(3, 0) + SPILL(c[4]);
212 c[2] = M(0, 2) + M(1, 1) + M(2, 0) + SPILL(c[3]);
213 c[1] = M(0, 1) + M(1, 0) + SPILL(c[2]);
214 c[0] = M(0, 0) + SPILL(c[1]);
217 f[1] = C(c[1], c[2]);
218 f[2] = C(c[3], c[4]);
219 f[3] = C(c[5], c[6]);
221 if((f[0] & HiddenBit) == 0){
248 fpidiv(Internal *x, Internal *y, Internal *i)
251 if(IsNaN(x) || IsNaN(y)
252 || (IsInfinity(x) && IsInfinity(y)) || (IsZero(x) && IsZero(y))){
256 else if(IsZero(x) || IsInfinity(y)){
260 else if(IsInfinity(x) || IsZero(y)){
268 i->e = y->e - x->e + (ExpBias + 2*FractBits - 1);
270 if(y->h > x->h || (y->h == x->h && y->l >= x->l)){
281 }while ((i->h & HiddenBit) == 0);
288 fpicmp(Internal *x, Internal *y)
290 if(IsNaN(x) && IsNaN(y))
292 if(IsInfinity(x) && IsInfinity(y))
294 if(x->e == y->e && x->h == y->h && x->l == y->l)
297 || (x->e == y->e && (x->h < y->h || (x->h == y->h && x->l < y->l))))