Changeset f37d769 in mainline for softfloat/generic/conversion.c


Ignore:
Timestamp:
2006-02-24T18:24:07Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fbd6f81
Parents:
ba5870d
Message:

Int32 and int64 → double conversions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • softfloat/generic/conversion.c

    rba5870d rf37d769  
    387387}       
    388388
    389        
    390389/** Convert unsigned integer to float32
    391390 *
     
    486485        return result;
    487486}
     487
     488/** Convert unsigned integer to float64
     489 *
     490 *
     491 */
     492float64 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
     522float64 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
     538float64 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
     569float64 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
Note: See TracChangeset for help on using the changeset viewer.