Ignore:
Timestamp:
2012-04-08T12:08:49Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f2b3d3e
Parents:
d9f53877 (diff), f3378ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/softfloat/generic/conversion.c

    rd9f53877 r90924df  
    3939#include <common.h>
    4040
    41 float64 convertFloat32ToFloat64(float32 a)
     41float64 float32_to_float64(float32 a)
    4242{
    4343        float64 result;
     
    4848        result.parts.fraction <<= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE);
    4949       
    50         if ((isFloat32Infinity(a)) || (isFloat32NaN(a))) {
     50        if ((is_float32_infinity(a)) || (is_float32_nan(a))) {
    5151                result.parts.exp = FLOAT64_MAX_EXPONENT;
    52                 /* TODO; check if its correct for SigNaNs*/
     52                // TODO; check if its correct for SigNaNs
    5353                return result;
    5454        }
     
    5757        if (a.parts.exp == 0) {
    5858                /* normalize denormalized numbers */
    59 
     59               
    6060                if (result.parts.fraction == 0) { /* fix zero */
    6161                        result.parts.exp = 0;
     
    7777}
    7878
    79 float128 convertFloat32ToFloat128(float32 a)
     79float128 float32_to_float128(float32 a)
    8080{
    8181        float128 result;
    8282        uint64_t frac_hi, frac_lo;
    8383        uint64_t tmp_hi, tmp_lo;
    84 
     84       
    8585        result.parts.sign = a.parts.sign;
    8686        result.parts.frac_hi = 0;
     
    9191        result.parts.frac_hi = frac_hi;
    9292        result.parts.frac_lo = frac_lo;
    93 
    94         if ((isFloat32Infinity(a)) || (isFloat32NaN(a))) {
     93       
     94        if ((is_float32_infinity(a)) || (is_float32_nan(a))) {
    9595                result.parts.exp = FLOAT128_MAX_EXPONENT;
    96                 /* TODO; check if its correct for SigNaNs*/
    97                 return result;
    98         }
    99 
     96                // TODO; check if its correct for SigNaNs
     97                return result;
     98        }
     99       
    100100        result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT32_BIAS);
    101101        if (a.parts.exp == 0) {
    102102                /* normalize denormalized numbers */
    103 
     103               
    104104                if (eq128(result.parts.frac_hi,
    105105                    result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */
     
    107107                        return result;
    108108                }
    109 
     109               
    110110                frac_hi = result.parts.frac_hi;
    111111                frac_lo = result.parts.frac_lo;
    112 
     112               
    113113                and128(frac_hi, frac_lo,
    114114                    FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
     
    118118                        --result.parts.exp;
    119119                }
    120 
     120               
    121121                ++result.parts.exp;
    122122                result.parts.frac_hi = frac_hi;
    123123                result.parts.frac_lo = frac_lo;
    124124        }
    125 
    126         return result;
    127 }
    128 
    129 float128 convertFloat64ToFloat128(float64 a)
     125       
     126        return result;
     127}
     128
     129float128 float64_to_float128(float64 a)
    130130{
    131131        float128 result;
    132132        uint64_t frac_hi, frac_lo;
    133133        uint64_t tmp_hi, tmp_lo;
    134 
     134       
    135135        result.parts.sign = a.parts.sign;
    136136        result.parts.frac_hi = 0;
     
    141141        result.parts.frac_hi = frac_hi;
    142142        result.parts.frac_lo = frac_lo;
    143 
    144         if ((isFloat64Infinity(a)) || (isFloat64NaN(a))) {
     143       
     144        if ((is_float64_infinity(a)) || (is_float64_nan(a))) {
    145145                result.parts.exp = FLOAT128_MAX_EXPONENT;
    146                 /* TODO; check if its correct for SigNaNs*/
    147                 return result;
    148         }
    149 
     146                // TODO; check if its correct for SigNaNs
     147                return result;
     148        }
     149       
    150150        result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT64_BIAS);
    151151        if (a.parts.exp == 0) {
    152152                /* normalize denormalized numbers */
    153 
     153               
    154154                if (eq128(result.parts.frac_hi,
    155155                    result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */
     
    157157                        return result;
    158158                }
    159 
     159               
    160160                frac_hi = result.parts.frac_hi;
    161161                frac_lo = result.parts.frac_lo;
    162 
     162               
    163163                and128(frac_hi, frac_lo,
    164164                    FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
     
    168168                        --result.parts.exp;
    169169                }
    170 
     170               
    171171                ++result.parts.exp;
    172172                result.parts.frac_hi = frac_hi;
    173173                result.parts.frac_lo = frac_lo;
    174174        }
    175 
    176         return result;
    177 }
    178 
    179 float32 convertFloat64ToFloat32(float64 a)
     175       
     176        return result;
     177}
     178
     179float32 float64_to_float32(float64 a)
    180180{
    181181        float32 result;
     
    185185        result.parts.sign = a.parts.sign;
    186186       
    187         if (isFloat64NaN(a)) {
     187        if (is_float64_nan(a)) {
    188188                result.parts.exp = FLOAT32_MAX_EXPONENT;
    189189               
    190                 if (isFloat64SigNaN(a)) {
     190                if (is_float64_signan(a)) {
    191191                        /* set first bit of fraction nonzero */
    192192                        result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1;
    193193                        return result;
    194194                }
    195 
     195               
    196196                /* fraction nonzero but its first bit is zero */
    197197                result.parts.fraction = 0x1;
    198198                return result;
    199199        }
    200 
    201         if (isFloat64Infinity(a)) {
     200       
     201        if (is_float64_infinity(a)) {
    202202                result.parts.fraction = 0;
    203203                result.parts.exp = FLOAT32_MAX_EXPONENT;
    204204                return result;
    205205        }
    206 
     206       
    207207        exp = (int) a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS;
    208208       
     
    239239                return result;
    240240        }
    241 
     241       
    242242        result.parts.exp = exp;
    243243        result.parts.fraction =
     
    246246}
    247247
    248 float32 convertFloat128ToFloat32(float128 a)
     248float32 float128_to_float32(float128 a)
    249249{
    250250        float32 result;
    251251        int32_t exp;
    252252        uint64_t frac_hi, frac_lo;
    253 
     253       
    254254        result.parts.sign = a.parts.sign;
    255 
    256         if (isFloat128NaN(a)) {
     255       
     256        if (is_float128_nan(a)) {
    257257                result.parts.exp = FLOAT32_MAX_EXPONENT;
    258 
    259                 if (isFloat128SigNaN(a)) {
     258               
     259                if (is_float128_signan(a)) {
    260260                        /* set first bit of fraction nonzero */
    261261                        result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1;
    262262                        return result;
    263263                }
    264 
     264               
    265265                /* fraction nonzero but its first bit is zero */
    266266                result.parts.fraction = 0x1;
    267267                return result;
    268268        }
    269 
    270         if (isFloat128Infinity(a)) {
     269       
     270        if (is_float128_infinity(a)) {
    271271                result.parts.fraction = 0;
    272272                result.parts.exp = FLOAT32_MAX_EXPONENT;
    273273                return result;
    274274        }
    275 
     275       
    276276        exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT32_BIAS;
    277 
     277       
    278278        if (exp >= FLOAT32_MAX_EXPONENT) {
    279279                /* FIXME: overflow */
     
    283283        } else if (exp <= 0) {
    284284                /* underflow or denormalized */
    285 
     285               
    286286                result.parts.exp = 0;
    287 
     287               
    288288                exp *= -1;
    289289                if (exp > FLOAT32_FRACTION_SIZE) {
     
    292292                        return result;
    293293                }
    294 
     294               
    295295                /* denormalized */
    296 
     296               
    297297                frac_hi = a.parts.frac_hi;
    298298                frac_lo = a.parts.frac_lo;
    299 
     299               
    300300                /* denormalize and set hidden bit */
    301301                frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
    302 
     302               
    303303                rshift128(frac_hi, frac_lo,
    304304                    (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1),
    305305                    &frac_hi, &frac_lo);
    306 
     306               
    307307                while (exp > 0) {
    308308                        --exp;
     
    310310                }
    311311                result.parts.fraction = frac_lo;
    312 
    313                 return result;
    314         }
    315 
     312               
     313                return result;
     314        }
     315       
    316316        result.parts.exp = exp;
    317317        frac_hi = a.parts.frac_hi;
     
    324324}
    325325
    326 float64 convertFloat128ToFloat64(float128 a)
     326float64 float128_to_float64(float128 a)
    327327{
    328328        float64 result;
    329329        int32_t exp;
    330330        uint64_t frac_hi, frac_lo;
    331 
     331       
    332332        result.parts.sign = a.parts.sign;
    333 
    334         if (isFloat128NaN(a)) {
     333       
     334        if (is_float128_nan(a)) {
    335335                result.parts.exp = FLOAT64_MAX_EXPONENT;
    336 
    337                 if (isFloat128SigNaN(a)) {
     336               
     337                if (is_float128_signan(a)) {
    338338                        /* set first bit of fraction nonzero */
    339339                        result.parts.fraction = FLOAT64_HIDDEN_BIT_MASK >> 1;
    340340                        return result;
    341341                }
    342 
     342               
    343343                /* fraction nonzero but its first bit is zero */
    344344                result.parts.fraction = 0x1;
    345345                return result;
    346346        }
    347 
    348         if (isFloat128Infinity(a)) {
     347       
     348        if (is_float128_infinity(a)) {
    349349                result.parts.fraction = 0;
    350350                result.parts.exp = FLOAT64_MAX_EXPONENT;
    351351                return result;
    352352        }
    353 
     353       
    354354        exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT64_BIAS;
    355 
     355       
    356356        if (exp >= FLOAT64_MAX_EXPONENT) {
    357357                /* FIXME: overflow */
     
    361361        } else if (exp <= 0) {
    362362                /* underflow or denormalized */
    363 
     363               
    364364                result.parts.exp = 0;
    365 
     365               
    366366                exp *= -1;
    367367                if (exp > FLOAT64_FRACTION_SIZE) {
     
    370370                        return result;
    371371                }
    372 
     372               
    373373                /* denormalized */
    374 
     374               
    375375                frac_hi = a.parts.frac_hi;
    376376                frac_lo = a.parts.frac_lo;
    377 
     377               
    378378                /* denormalize and set hidden bit */
    379379                frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
    380 
     380               
    381381                rshift128(frac_hi, frac_lo,
    382382                    (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE + 1),
    383383                    &frac_hi, &frac_lo);
    384 
     384               
    385385                while (exp > 0) {
    386386                        --exp;
     
    388388                }
    389389                result.parts.fraction = frac_lo;
    390 
    391                 return result;
    392         }
    393 
     390               
     391                return result;
     392        }
     393       
    394394        result.parts.exp = exp;
    395395        frac_hi = a.parts.frac_hi;
     
    402402}
    403403
    404 
    405 /**
    406  * Helping procedure for converting float32 to uint32.
     404/** Helper procedure for converting float32 to uint32.
    407405 *
    408406 * @param a Floating point number in normalized form
     
    424422        /* shift fraction to left so hidden bit will be the most significant bit */
    425423        frac <<= 32 - FLOAT32_FRACTION_SIZE - 1;
    426 
     424       
    427425        frac >>= 32 - (a.parts.exp - FLOAT32_BIAS) - 1;
    428426        if ((a.parts.sign == 1) && (frac != 0)) {
     
    434432}
    435433
    436 /* 
    437  * FIXME: Im not sure what to return if overflow/underflow happens 
    438  *      - now its the biggest or the smallest int
    439  */ 
     434/*
     435 * FIXME: Im not sure what to return if overflow/underflow happens
     436 *  - now its the biggest or the smallest int
     437 */
    440438uint32_t float32_to_uint32(float32 a)
    441439{
    442         if (isFloat32NaN(a))
     440        if (is_float32_nan(a))
    443441                return UINT32_MAX;
    444442       
    445         if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
     443        if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
    446444                if (a.parts.sign)
    447445                        return UINT32_MIN;
     
    453451}
    454452
    455 /* 
    456  * FIXME: Im not sure what to return if overflow/underflow happens 
    457  *      - now its the biggest or the smallest int
    458  */ 
     453/*
     454 * FIXME: Im not sure what to return if overflow/underflow happens
     455 *  - now its the biggest or the smallest int
     456 */
    459457int32_t float32_to_int32(float32 a)
    460458{
    461         if (isFloat32NaN(a))
     459        if (is_float32_nan(a))
    462460                return INT32_MAX;
    463461       
    464         if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
     462        if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
    465463                if (a.parts.sign)
    466464                        return INT32_MIN;
     
    472470}
    473471
    474 
    475 /**
    476  * Helping procedure for converting float32 to uint64.
     472/** Helper procedure for converting float32 to uint64.
    477473 *
    478474 * @param a Floating point number in normalized form
     
    483479{
    484480        uint64_t frac;
    485 
     481       
    486482        if (a.parts.exp < FLOAT32_BIAS) {
    487                 /*TODO: rounding*/
     483                // TODO: rounding
    488484                return 0;
    489485        }
    490 
     486       
    491487        frac = a.parts.fraction;
    492 
     488       
    493489        frac |= FLOAT32_HIDDEN_BIT_MASK;
    494490        /* shift fraction to left so hidden bit will be the most significant bit */
    495491        frac <<= 64 - FLOAT32_FRACTION_SIZE - 1;
    496 
     492       
    497493        frac >>= 64 - (a.parts.exp - FLOAT32_BIAS) - 1;
    498494        if ((a.parts.sign == 1) && (frac != 0)) {
     
    500496                ++frac;
    501497        }
    502 
     498       
    503499        return frac;
    504500}
    505501
    506 /* 
     502/*
    507503 * FIXME: Im not sure what to return if overflow/underflow happens
    508  *      - now its the biggest or the smallest int
     504 *  - now its the biggest or the smallest int
    509505 */
    510506uint64_t float32_to_uint64(float32 a)
    511507{
    512         if (isFloat32NaN(a))
     508        if (is_float32_nan(a))
    513509                return UINT64_MAX;
    514 
    515 
    516         if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
     510       
     511        if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
    517512                if (a.parts.sign)
    518513                        return UINT64_MIN;
    519 
     514               
    520515                return UINT64_MAX;
    521516        }
    522 
     517       
    523518        return _float32_to_uint64_helper(a);
    524519}
    525520
    526 /* 
     521/*
    527522 * FIXME: Im not sure what to return if overflow/underflow happens
    528  *      - now its the biggest or the smallest int
     523 *  - now its the biggest or the smallest int
    529524 */
    530525int64_t float32_to_int64(float32 a)
    531526{
    532         if (isFloat32NaN(a))
     527        if (is_float32_nan(a))
    533528                return INT64_MAX;
    534 
    535         if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
     529       
     530        if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
    536531                if (a.parts.sign)
    537532                        return INT64_MIN;
    538 
     533               
    539534                return INT64_MAX;
    540535        }
    541 
     536       
    542537        return _float32_to_uint64_helper(a);
    543538}
    544539
    545 
    546 /**
    547  * Helping procedure for converting float64 to uint64.
     540/** Helper procedure for converting float64 to uint64.
    548541 *
    549542 * @param a Floating point number in normalized form
     
    554547{
    555548        uint64_t frac;
    556 
     549       
    557550        if (a.parts.exp < FLOAT64_BIAS) {
    558                 /*TODO: rounding*/
     551                // TODO: rounding
    559552                return 0;
    560553        }
    561 
     554       
    562555        frac = a.parts.fraction;
    563 
     556       
    564557        frac |= FLOAT64_HIDDEN_BIT_MASK;
    565558        /* shift fraction to left so hidden bit will be the most significant bit */
    566559        frac <<= 64 - FLOAT64_FRACTION_SIZE - 1;
    567 
     560       
    568561        frac >>= 64 - (a.parts.exp - FLOAT64_BIAS) - 1;
    569562        if ((a.parts.sign == 1) && (frac != 0)) {
     
    571564                ++frac;
    572565        }
    573 
     566       
    574567        return frac;
    575568}
     
    577570/*
    578571 * FIXME: Im not sure what to return if overflow/underflow happens
    579  *      - now its the biggest or the smallest int
     572 *  - now its the biggest or the smallest int
    580573 */
    581574uint32_t float64_to_uint32(float64 a)
    582575{
    583         if (isFloat64NaN(a))
     576        if (is_float64_nan(a))
    584577                return UINT32_MAX;
    585 
    586         if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
     578       
     579        if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
    587580                if (a.parts.sign)
    588581                        return UINT32_MIN;
    589 
     582               
    590583                return UINT32_MAX;
    591584        }
    592 
     585       
    593586        return (uint32_t) _float64_to_uint64_helper(a);
    594587}
     
    596589/*
    597590 * FIXME: Im not sure what to return if overflow/underflow happens
    598  *      - now its the biggest or the smallest int
     591 *  - now its the biggest or the smallest int
    599592 */
    600593int32_t float64_to_int32(float64 a)
    601594{
    602         if (isFloat64NaN(a))
     595        if (is_float64_nan(a))
    603596                return INT32_MAX;
    604 
    605         if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
     597       
     598        if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
    606599                if (a.parts.sign)
    607600                        return INT32_MIN;
    608 
     601               
    609602                return INT32_MAX;
    610603        }
    611 
     604       
    612605        return (int32_t) _float64_to_uint64_helper(a);
    613606}
    614607
    615 
    616 /*
     608/*
    617609 * FIXME: Im not sure what to return if overflow/underflow happens
    618  *      - now its the biggest or the smallest int
    619  */ 
     610 *  - now its the biggest or the smallest int
     611 */
    620612uint64_t float64_to_uint64(float64 a)
    621613{
    622         if (isFloat64NaN(a))
     614        if (is_float64_nan(a))
    623615                return UINT64_MAX;
    624616       
    625         if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
     617        if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
    626618                if (a.parts.sign)
    627619                        return UINT64_MIN;
     
    633625}
    634626
    635 /* 
     627/*
    636628 * FIXME: Im not sure what to return if overflow/underflow happens
    637  *      - now its the biggest or the smallest int
    638  */ 
     629 *  - now its the biggest or the smallest int
     630 */
    639631int64_t float64_to_int64(float64 a)
    640632{
    641         if (isFloat64NaN(a))
     633        if (is_float64_nan(a))
    642634                return INT64_MAX;
    643635       
    644         if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
     636        if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
    645637                if (a.parts.sign)
    646638                        return INT64_MIN;
     
    652644}
    653645
    654 
    655 /**
    656  * Helping procedure for converting float128 to uint64.
     646/** Helper procedure for converting float128 to uint64.
    657647 *
    658648 * @param a Floating point number in normalized form
     
    663653{
    664654        uint64_t frac_hi, frac_lo;
    665 
     655       
    666656        if (a.parts.exp < FLOAT128_BIAS) {
    667                 /*TODO: rounding*/
     657                // TODO: rounding
    668658                return 0;
    669659        }
    670 
     660       
    671661        frac_hi = a.parts.frac_hi;
    672662        frac_lo = a.parts.frac_lo;
    673 
     663       
    674664        frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
    675665        /* shift fraction to left so hidden bit will be the most significant bit */
    676666        lshift128(frac_hi, frac_lo,
    677667            (128 - FLOAT128_FRACTION_SIZE - 1), &frac_hi, &frac_lo);
    678 
     668       
    679669        rshift128(frac_hi, frac_lo,
    680670            (128 - (a.parts.exp - FLOAT128_BIAS) - 1), &frac_hi, &frac_lo);
     
    683673                add128(frac_hi, frac_lo, 0x0ll, 0x1ll, &frac_hi, &frac_lo);
    684674        }
    685 
     675       
    686676        return frac_lo;
    687677}
     
    689679/*
    690680 * FIXME: Im not sure what to return if overflow/underflow happens
    691  *      - now its the biggest or the smallest int
     681 *  - now its the biggest or the smallest int
    692682 */
    693683uint32_t float128_to_uint32(float128 a)
    694684{
    695         if (isFloat128NaN(a))
     685        if (is_float128_nan(a))
    696686                return UINT32_MAX;
    697 
    698         if (isFloat128Infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
     687       
     688        if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
    699689                if (a.parts.sign)
    700690                        return UINT32_MIN;
    701 
     691               
    702692                return UINT32_MAX;
    703693        }
    704 
     694       
    705695        return (uint32_t) _float128_to_uint64_helper(a);
    706696}
     
    708698/*
    709699 * FIXME: Im not sure what to return if overflow/underflow happens
    710  *      - now its the biggest or the smallest int
     700 *  - now its the biggest or the smallest int
    711701 */
    712702int32_t float128_to_int32(float128 a)
    713703{
    714         if (isFloat128NaN(a))
     704        if (is_float128_nan(a))
    715705                return INT32_MAX;
    716 
    717         if (isFloat128Infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
     706       
     707        if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
    718708                if (a.parts.sign)
    719709                        return INT32_MIN;
    720 
     710               
    721711                return INT32_MAX;
    722712        }
    723 
     713       
    724714        return (int32_t) _float128_to_uint64_helper(a);
    725715}
    726716
    727 
    728717/*
    729718 * FIXME: Im not sure what to return if overflow/underflow happens
    730  *      - now its the biggest or the smallest int
     719 *  - now its the biggest or the smallest int
    731720 */
    732721uint64_t float128_to_uint64(float128 a)
    733722{
    734         if (isFloat128NaN(a))
     723        if (is_float128_nan(a))
    735724                return UINT64_MAX;
    736 
    737         if (isFloat128Infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
     725       
     726        if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
    738727                if (a.parts.sign)
    739728                        return UINT64_MIN;
    740 
     729               
    741730                return UINT64_MAX;
    742731        }
    743 
     732       
    744733        return _float128_to_uint64_helper(a);
    745734}
     
    747736/*
    748737 * FIXME: Im not sure what to return if overflow/underflow happens
    749  *      - now its the biggest or the smallest int
     738 *  - now its the biggest or the smallest int
    750739 */
    751740int64_t float128_to_int64(float128 a)
    752741{
    753         if (isFloat128NaN(a))
     742        if (is_float128_nan(a))
    754743                return INT64_MAX;
    755 
    756         if (isFloat128Infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
     744       
     745        if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
    757746                if (a.parts.sign)
    758747                        return INT64_MIN;
    759 
     748               
    760749                return INT64_MAX;
    761750        }
    762 
     751       
    763752        return _float128_to_uint64_helper(a);
    764753}
    765 
    766754
    767755float32 uint32_to_float32(uint32_t i)
     
    773761        result.parts.sign = 0;
    774762        result.parts.fraction = 0;
    775 
    776         counter = countZeroes32(i);
    777 
     763       
     764        counter = count_zeroes32(i);
     765       
    778766        exp = FLOAT32_BIAS + 32 - counter - 1;
    779767       
    780768        if (counter == 32) {
    781                 result.binary = 0;
     769                result.bin = 0;
    782770                return result;
    783771        }
     
    788776                i >>= 1;
    789777        }
    790 
    791         roundFloat32(&exp, &i);
    792 
     778       
     779        round_float32(&exp, &i);
     780       
    793781        result.parts.fraction = i >> (32 - FLOAT32_FRACTION_SIZE - 2);
    794782        result.parts.exp = exp;
    795 
    796         return result;
    797 }
    798 
    799 float32 int32_to_float32(int32_t i) 
     783       
     784        return result;
     785}
     786
     787float32 int32_to_float32(int32_t i)
    800788{
    801789        float32 result;
    802 
    803         if (i < 0) {
     790       
     791        if (i < 0)
    804792                result = uint32_to_float32((uint32_t) (-i));
    805         } else {
     793        else
    806794                result = uint32_to_float32((uint32_t) i);
    807         }
    808795       
    809796        result.parts.sign = i < 0;
    810 
    811         return result;
    812 }
    813 
    814 
    815 float32 uint64_to_float32(uint64_t i)
     797       
     798        return result;
     799}
     800
     801float32 uint64_to_float32(uint64_t i)
    816802{
    817803        int counter;
     
    822808        result.parts.sign = 0;
    823809        result.parts.fraction = 0;
    824 
    825         counter = countZeroes64(i);
    826 
     810       
     811        counter = count_zeroes64(i);
     812       
    827813        exp = FLOAT32_BIAS + 64 - counter - 1;
    828814       
    829815        if (counter == 64) {
    830                 result.binary = 0;
     816                result.bin = 0;
    831817                return result;
    832818        }
     
    840826       
    841827        j = (uint32_t) i;
    842         roundFloat32(&exp, &j);
    843 
     828        round_float32(&exp, &j);
     829       
    844830        result.parts.fraction = j >> (32 - FLOAT32_FRACTION_SIZE - 2);
    845831        result.parts.exp = exp;
     
    847833}
    848834
    849 float32 int64_to_float32(int64_t i) 
     835float32 int64_to_float32(int64_t i)
    850836{
    851837        float32 result;
    852 
    853         if (i < 0) {
     838       
     839        if (i < 0)
    854840                result = uint64_to_float32((uint64_t) (-i));
    855         } else {
     841        else
    856842                result = uint64_to_float32((uint64_t) i);
    857         }
    858843       
    859844        result.parts.sign = i < 0;
    860 
    861         return result;
     845       
     846        return result;
    862847}
    863848
     
    871856        result.parts.sign = 0;
    872857        result.parts.fraction = 0;
    873 
    874         counter = countZeroes32(i);
    875 
     858       
     859        counter = count_zeroes32(i);
     860       
    876861        exp = FLOAT64_BIAS + 32 - counter - 1;
    877862       
    878863        if (counter == 32) {
    879                 result.binary = 0;
     864                result.bin = 0;
    880865                return result;
    881866        }
    882867       
    883868        frac = i;
    884         frac <<= counter + 32 - 1; 
    885 
    886         roundFloat64(&exp, &frac);
    887 
     869        frac <<= counter + 32 - 1;
     870       
     871        round_float64(&exp, &frac);
     872       
    888873        result.parts.fraction = frac >> (64 - FLOAT64_FRACTION_SIZE - 2);
    889874        result.parts.exp = exp;
    890 
    891         return result;
    892 }
    893 
    894 float64 int32_to_float64(int32_t i) 
     875       
     876        return result;
     877}
     878
     879float64 int32_to_float64(int32_t i)
    895880{
    896881        float64 result;
    897 
    898         if (i < 0) {
     882       
     883        if (i < 0)
    899884                result = uint32_to_float64((uint32_t) (-i));
    900         } else {
     885        else
    901886                result = uint32_to_float64((uint32_t) i);
    902         }
    903887       
    904888        result.parts.sign = i < 0;
    905 
    906         return result;
    907 }
    908 
    909 
    910 float64 uint64_to_float64(uint64_t i) 
     889       
     890        return result;
     891}
     892
     893
     894float64 uint64_to_float64(uint64_t i)
    911895{
    912896        int counter;
     
    916900        result.parts.sign = 0;
    917901        result.parts.fraction = 0;
    918 
    919         counter = countZeroes64(i);
    920 
     902       
     903        counter = count_zeroes64(i);
     904       
    921905        exp = FLOAT64_BIAS + 64 - counter - 1;
    922906       
    923907        if (counter == 64) {
    924                 result.binary = 0;
     908                result.bin = 0;
    925909                return result;
    926910        }
     
    931915                i >>= 1;
    932916        }
    933 
    934         roundFloat64(&exp, &i);
    935 
     917       
     918        round_float64(&exp, &i);
     919       
    936920        result.parts.fraction = i >> (64 - FLOAT64_FRACTION_SIZE - 2);
    937921        result.parts.exp = exp;
     
    939923}
    940924
    941 float64 int64_to_float64(int64_t i) 
     925float64 int64_to_float64(int64_t i)
    942926{
    943927        float64 result;
    944 
    945         if (i < 0) {
     928       
     929        if (i < 0)
    946930                result = uint64_to_float64((uint64_t) (-i));
    947         } else {
     931        else
    948932                result = uint64_to_float64((uint64_t) i);
    949         }
    950933       
    951934        result.parts.sign = i < 0;
    952 
    953         return result;
    954 }
    955 
     935       
     936        return result;
     937}
    956938
    957939float128 uint32_to_float128(uint32_t i)
     
    961943        float128 result;
    962944        uint64_t frac_hi, frac_lo;
    963 
     945       
    964946        result.parts.sign = 0;
    965947        result.parts.frac_hi = 0;
    966948        result.parts.frac_lo = 0;
    967 
    968         counter = countZeroes32(i);
    969 
     949       
     950        counter = count_zeroes32(i);
     951       
    970952        exp = FLOAT128_BIAS + 32 - counter - 1;
    971 
     953       
    972954        if (counter == 32) {
    973                 result.binary.hi = 0;
    974                 result.binary.lo = 0;
    975                 return result;
    976         }
    977 
     955                result.bin.hi = 0;
     956                result.bin.lo = 0;
     957                return result;
     958        }
     959       
    978960        frac_hi = 0;
    979961        frac_lo = i;
    980962        lshift128(frac_hi, frac_lo, (counter + 96 - 1), &frac_hi, &frac_lo);
    981 
    982         roundFloat128(&exp, &frac_hi, &frac_lo);
    983 
     963       
     964        round_float128(&exp, &frac_hi, &frac_lo);
     965       
    984966        rshift128(frac_hi, frac_lo,
    985967            (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo);
     
    987969        result.parts.frac_lo = frac_lo;
    988970        result.parts.exp = exp;
    989 
     971       
    990972        return result;
    991973}
     
    994976{
    995977        float128 result;
    996 
    997         if (i < 0) {
     978       
     979        if (i < 0)
    998980                result = uint32_to_float128((uint32_t) (-i));
    999         } else {
     981        else
    1000982                result = uint32_to_float128((uint32_t) i);
    1001         }
    1002 
     983       
    1003984        result.parts.sign = i < 0;
    1004 
    1005         return result;
     985       
     986        return result;
    1006987}
    1007988
     
    1013994        float128 result;
    1014995        uint64_t frac_hi, frac_lo;
    1015 
     996       
    1016997        result.parts.sign = 0;
    1017998        result.parts.frac_hi = 0;
    1018999        result.parts.frac_lo = 0;
    1019 
    1020         counter = countZeroes64(i);
    1021 
     1000       
     1001        counter = count_zeroes64(i);
     1002       
    10221003        exp = FLOAT128_BIAS + 64 - counter - 1;
    1023 
     1004       
    10241005        if (counter == 64) {
    1025                 result.binary.hi = 0;
    1026                 result.binary.lo = 0;
    1027                 return result;
    1028         }
    1029 
     1006                result.bin.hi = 0;
     1007                result.bin.lo = 0;
     1008                return result;
     1009        }
     1010       
    10301011        frac_hi = 0;
    10311012        frac_lo = i;
    10321013        lshift128(frac_hi, frac_lo, (counter + 64 - 1), &frac_hi, &frac_lo);
    1033 
    1034         roundFloat128(&exp, &frac_hi, &frac_lo);
    1035 
     1014       
     1015        round_float128(&exp, &frac_hi, &frac_lo);
     1016       
    10361017        rshift128(frac_hi, frac_lo,
    10371018            (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo);
     
    10391020        result.parts.frac_lo = frac_lo;
    10401021        result.parts.exp = exp;
    1041 
     1022       
    10421023        return result;
    10431024}
     
    10461027{
    10471028        float128 result;
    1048 
    1049         if (i < 0) {
     1029       
     1030        if (i < 0)
    10501031                result = uint64_to_float128((uint64_t) (-i));
    1051         } else {
     1032        else
    10521033                result = uint64_to_float128((uint64_t) i);
    1053         }
    1054 
     1034       
    10551035        result.parts.sign = i < 0;
    1056 
    1057         return result;
     1036       
     1037        return result;
    10581038}
    10591039
Note: See TracChangeset for help on using the changeset viewer.