Subversion Repositories HelenOS-historic

Rev

Rev 661 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 661 Rev 688
Line 41... Line 41...
41
    if (expdiff<0) {
41
    if (expdiff<0) {
42
        if (isFloat32NaN(b)) {
42
        if (isFloat32NaN(b)) {
43
            //TODO: fix SigNaN
43
            //TODO: fix SigNaN
44
            if (isFloat32SigNaN(b)) {
44
            if (isFloat32SigNaN(b)) {
45
            };
45
            };
-
 
46
 
46
            return b;
47
            return b;
47
        };
48
        };
48
       
49
       
49
        if (b.parts.exp==0xFF) {
50
        if (b.parts.exp==0xFF) {
50
            return b;
51
            return b;
Line 216... Line 217...
216
    while ((exp1>0)&&(!(mant1&0x20000000))) {
217
    while ((exp1>0)&&(!(mant1&0x20000000))) {
217
        exp1--;
218
        exp1--;
218
        mant1 <<= 1;
219
        mant1 <<= 1;
219
        if(mant1 == 0) {
220
        if(mant1 == 0) {
220
            /* Realy is it an underflow? ... */
221
            /* Realy is it an underflow? ... */
221
            //TODO: fix underflow
222
            /* TODO: fix underflow */
222
        };
223
        };
223
    };
224
    };
224
   
225
   
225
    //rounding - if first bit after mantisa is set then round up    
226
    //rounding - if first bit after mantisa is set then round up    
226
    mant1 += 0x20;
227
    mant1 += 0x20;
Line 234... Line 235...
234
    result.parts.exp = exp1;
235
    result.parts.exp = exp1;
235
   
236
   
236
    return result;
237
    return result;
237
};
238
};
238
 
239
 
-
 
240
/** Multiply two 32 bit float numbers
-
 
241
 *
-
 
242
 */
-
 
243
float32 mulFloat32(float32 a, float32 b)
-
 
244
{
-
 
245
    float32 result;
-
 
246
    __u64 mant1, mant2;
-
 
247
    __s32 exp;
-
 
248
 
-
 
249
    result.parts.sign = a.parts.sign ^ b.parts.sign;
-
 
250
   
-
 
251
    if ((isFloat32NaN(a))||(isFloat32NaN(b))) {
-
 
252
        /* TODO: fix SigNaNs */
-
 
253
        if (isFloat32SigNaN(a)) {
-
 
254
            result.parts.mantisa = a.parts.mantisa;
-
 
255
            result.parts.exp = a.parts.exp;
-
 
256
            return result;
-
 
257
        };
-
 
258
        if (isFloat32SigNaN(b)) { /* TODO: fix SigNaN */
-
 
259
            result.parts.mantisa = b.parts.mantisa;
-
 
260
            result.parts.exp = b.parts.exp;
-
 
261
            return result;
-
 
262
        };
-
 
263
        /* set NaN as result */
-
 
264
        result.parts.mantisa = 0x1;
-
 
265
        result.parts.exp = 0xFF;
-
 
266
        return result;
-
 
267
    };
-
 
268
       
-
 
269
    if (isFloat32Infinity(a)) {
-
 
270
        if (isFloat32Zero(b)) {
-
 
271
            /* FIXME: zero * infinity */
-
 
272
            result.parts.mantisa = 0x1;
-
 
273
            result.parts.exp = 0xFF;
-
 
274
            return result;
-
 
275
        }
-
 
276
        result.parts.mantisa = a.parts.mantisa;
-
 
277
        result.parts.exp = a.parts.exp;
-
 
278
        return result;
-
 
279
    }
-
 
280
 
-
 
281
    if (isFloat32Infinity(b)) {
-
 
282
        if (isFloat32Zero(a)) {
-
 
283
            /* FIXME: zero * infinity */
-
 
284
            result.parts.mantisa = 0x1;
-
 
285
            result.parts.exp = 0xFF;
-
 
286
            return result;
-
 
287
        }
-
 
288
        result.parts.mantisa = b.parts.mantisa;
-
 
289
        result.parts.exp = b.parts.exp;
-
 
290
        return result;
-
 
291
    }
-
 
292
 
-
 
293
    /* exp is signed so we can easy detect underflow */
-
 
294
    exp = a.parts.exp + b.parts.exp;
-
 
295
    exp -= FLOAT32_BIAS;
-
 
296
   
-
 
297
    if (exp >= 0xFF ) {
-
 
298
        /* FIXME: overflow */
-
 
299
        /* set infinity as result */
-
 
300
        result.parts.mantisa = 0x0;
-
 
301
        result.parts.exp = 0xFF;
-
 
302
        return result;
-
 
303
    };
-
 
304
   
-
 
305
    if (exp < 0) {
-
 
306
        /* FIXME: underflow */
-
 
307
        /* return signed zero */
-
 
308
        result.parts.mantisa = 0x0;
-
 
309
        result.parts.exp = 0x0;
-
 
310
        return result;
-
 
311
    };
-
 
312
   
-
 
313
    mant1 = a.parts.mantisa;
-
 
314
    if (a.parts.exp>0) {
-
 
315
        mant1 |= 0x800000;
-
 
316
    } else {
-
 
317
        ++exp;
-
 
318
    };
-
 
319
   
-
 
320
    mant2 = b.parts.mantisa;
-
 
321
    if (b.parts.exp>0) {
-
 
322
        mant2 |= 0x800000;
-
 
323
    } else {
-
 
324
        ++exp;
-
 
325
    };
-
 
326
 
-
 
327
    mant1 <<= 1; /* one bit space for rounding */
-
 
328
 
-
 
329
    mant1 = mant1 * mant2;
-
 
330
/* round and return */
-
 
331
   
-
 
332
    while ((exp < 0xFF )&&(mant1 > 0x1FFFFFF )) { /* 0xFFFFFF is 23 bits of mantisa + one more for hidden bit (all shifted 1 bit left)*/
-
 
333
        ++exp;
-
 
334
        mant1 >>= 1;
-
 
335
    };
-
 
336
 
-
 
337
    /* rounding */
-
 
338
    //++mant1; /* FIXME: not works - without it is ok */
-
 
339
    mant1 >>= 1; /* shift off rounding space */
-
 
340
   
-
 
341
    if ((exp < 0xFF )&&(mant1 > 0xFFFFFF )) {
-
 
342
        ++exp;
-
 
343
        mant1 >>= 1;
-
 
344
    };
-
 
345
 
-
 
346
    if (exp >= 0xFF ) {
-
 
347
        /* TODO: fix overflow */
-
 
348
        /* return infinity*/
-
 
349
        result.parts.exp = 0xFF;
-
 
350
        result.parts.mantisa = 0x0;
-
 
351
        return result;
-
 
352
    }
-
 
353
   
-
 
354
    exp -= FLOAT32_MANTISA_SIZE;
-
 
355
 
-
 
356
    if (exp <= FLOAT32_MANTISA_SIZE) {
-
 
357
        /* denormalized number */
-
 
358
        mant1 >>= 1; /* denormalize */
-
 
359
        while ((mant1 > 0) && (exp < 0)) {
-
 
360
            mant1 >>= 1;
-
 
361
            ++exp;
-
 
362
        };
-
 
363
        if (mant1 == 0) {
-
 
364
            /* FIXME : underflow */
-
 
365
        result.parts.exp = 0;
-
 
366
        result.parts.mantisa = 0;
-
 
367
        return result;
-
 
368
        };
-
 
369
    };
-
 
370
    result.parts.exp = exp;
-
 
371
    result.parts.mantisa = mant1 & 0x7FFFFF;
-
 
372
   
-
 
373
    return result; 
-
 
374
   
-
 
375
};
-
 
376
 
-
 
377