Subversion Repositories HelenOS-historic

Rev

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

Rev 875 Rev 876
Line 384... Line 384...
384
        return MAX_INT32;
384
        return MAX_INT32;
385
    }
385
    }
386
    return (__s32)_float64_to_uint64_helper(a);
386
    return (__s32)_float64_to_uint64_helper(a);
387
}  
387
}  
388
 
388
 
389
   
-
 
390
/** Convert unsigned integer to float32
389
/** Convert unsigned integer to float32
391
 *
390
 *
392
 *
391
 *
393
 */
392
 */
394
float32 uint32_to_float32(__u32 i)
393
float32 uint32_to_float32(__u32 i)
Line 483... Line 482...
483
   
482
   
484
    result.parts.sign = i < 0;
483
    result.parts.sign = i < 0;
485
 
484
 
486
    return result;
485
    return result;
487
}
486
}
-
 
487
 
-
 
488
/** Convert unsigned integer to float64
-
 
489
 *
-
 
490
 *
-
 
491
 */
-
 
492
float64 uint32_to_float64(__u32 i)
-
 
493
{
-
 
494
    int counter;
-
 
495
    __s32 exp;
-
 
496
    float64 result;
-
 
497
    __u64 frac;
-
 
498
   
-
 
499
    result.parts.sign = 0;
-
 
500
    result.parts.fraction = 0;
-
 
501
 
-
 
502
    counter = countZeroes32(i);
-
 
503
 
-
 
504
    exp = FLOAT64_BIAS + 32 - counter - 1;
-
 
505
   
-
 
506
    if (counter == 32) {
-
 
507
        result.binary = 0;
-
 
508
        return result;
-
 
509
    }
-
 
510
   
-
 
511
    frac = i;
-
 
512
    frac <<= counter + 32 - 1;
-
 
513
 
-
 
514
    roundFloat64(&exp, &frac);
-
 
515
 
-
 
516
    result.parts.fraction = frac >> 10;
-
 
517
    result.parts.exp = exp;
-
 
518
 
-
 
519
    return result;
-
 
520
}
-
 
521
 
-
 
522
float64 int32_to_float64(__s32 i)
-
 
523
{
-
 
524
    float64 result;
-
 
525
 
-
 
526
    if (i < 0) {
-
 
527
        result = uint32_to_float64((__u32)(-i));
-
 
528
    } else {
-
 
529
        result = uint32_to_float64((__u32)i);
-
 
530
    }
-
 
531
   
-
 
532
    result.parts.sign = i < 0;
-
 
533
 
-
 
534
    return result;
-
 
535
}
-
 
536
 
-
 
537
 
-
 
538
float64 uint64_to_float64(__u64 i)
-
 
539
{
-
 
540
    int counter;
-
 
541
    __s32 exp;
-
 
542
    float64 result;
-
 
543
   
-
 
544
    result.parts.sign = 0;
-
 
545
    result.parts.fraction = 0;
-
 
546
 
-
 
547
    counter = countZeroes64(i);
-
 
548
 
-
 
549
    exp = FLOAT64_BIAS + 64 - counter - 1;
-
 
550
   
-
 
551
    if (counter == 64) {
-
 
552
        result.binary = 0;
-
 
553
        return result;
-
 
554
    }
-
 
555
   
-
 
556
    if (counter > 0) {
-
 
557
        i <<= counter - 1;
-
 
558
    } else {
-
 
559
        i >>= 1;
-
 
560
    }
-
 
561
 
-
 
562
    roundFloat64(&exp, &i);
-
 
563
 
-
 
564
    result.parts.fraction = i >> 10;
-
 
565
    result.parts.exp = exp;
-
 
566
    return result;
-
 
567
}
-
 
568
 
-
 
569
float64 int64_to_float64(__s64 i)
-
 
570
{
-
 
571
    float64 result;
-
 
572
 
-
 
573
    if (i < 0) {
-
 
574
        result = uint64_to_float64((__u64)(-i));
-
 
575
    } else {
-
 
576
        result = uint64_to_float64((__u64)i);
-
 
577
    }
-
 
578
   
-
 
579
    result.parts.sign = i < 0;
-
 
580
 
-
 
581
    return result;
-
 
582
}
-
 
583
 
-
 
584