Ignore:
File:
1 edited

Legend:

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

    r9d58539 r88d5c1e  
    4545 * @return 1 if float is NaN, 0 otherwise.
    4646 */
    47 int isFloat32NaN(float32 f)
     47int is_float32_nan(float32 f)
    4848{
    4949        /* NaN : exp = 0xff and nonzero fraction */
     
    5858 * @return 1 if float is NaN, 0 otherwise.
    5959 */
    60 int isFloat64NaN(float64 d)
     60int is_float64_nan(float64 d)
    6161{
    6262        /* NaN : exp = 0x7ff and nonzero fraction */
     
    7171 * @return 1 if float is NaN, 0 otherwise.
    7272 */
    73 int isFloat128NaN(float128 ld)
     73int is_float128_nan(float128 ld)
    7474{
    7575        /* NaN : exp = 0x7fff and nonzero fraction */
     
    8484 * @return 1 if float is signalling NaN, 0 otherwise.
    8585 */
    86 int isFloat32SigNaN(float32 f)
     86int is_float32_signan(float32 f)
    8787{
    8888        /* SigNaN : exp = 0xff and fraction = 0xxxxx..x (binary),
     
    9898 * @return 1 if float is signalling NaN, 0 otherwise.
    9999 */
    100 int isFloat64SigNaN(float64 d)
     100int is_float64_signan(float64 d)
    101101{
    102102        /* SigNaN : exp = 0x7ff and fraction = 0xxxxx..x (binary),
     
    112112 * @return 1 if float is signalling NaN, 0 otherwise.
    113113 */
    114 int isFloat128SigNaN(float128 ld)
     114int is_float128_signan(float128 ld)
    115115{
    116116        /* SigNaN : exp = 0x7fff and fraction = 0xxxxx..x (binary),
     
    128128 * @return 1 if float is infinite, 0 otherwise.
    129129 */
    130 int isFloat32Infinity(float32 f)
     130int is_float32_infinity(float32 f)
    131131{
    132132        /* NaN : exp = 0x7ff and zero fraction */
     
    140140 * @return 1 if float is infinite, 0 otherwise.
    141141 */
    142 int isFloat64Infinity(float64 d)
     142int is_float64_infinity(float64 d)
    143143{
    144144        /* NaN : exp = 0x7ff and zero fraction */
     
    152152 * @return 1 if float is infinite, 0 otherwise.
    153153 */
    154 int isFloat128Infinity(float128 ld)
     154int is_float128_infinity(float128 ld)
    155155{
    156156        /* NaN : exp = 0x7fff and zero fraction */
     
    165165 * @return 1 if float is zero, 0 otherwise.
    166166 */
    167 int isFloat32Zero(float32 f)
    168 {
    169         return (((f.binary) & 0x7FFFFFFF) == 0);
     167int is_float32_zero(float32 f)
     168{
     169        return (((f.bin) & 0x7FFFFFFF) == 0);
    170170}
    171171
     
    176176 * @return 1 if float is zero, 0 otherwise.
    177177 */
    178 int isFloat64Zero(float64 d)
    179 {
    180         return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0);
     178int is_float64_zero(float64 d)
     179{
     180        return (((d.bin) & 0x7FFFFFFFFFFFFFFFll) == 0);
    181181}
    182182
     
    187187 * @return 1 if float is zero, 0 otherwise.
    188188 */
    189 int isFloat128Zero(float128 ld)
     189int is_float128_zero(float128 ld)
    190190{
    191191        uint64_t tmp_hi;
    192192        uint64_t tmp_lo;
    193 
    194         and128(ld.binary.hi, ld.binary.lo,
     193       
     194        and128(ld.bin.hi, ld.bin.lo,
    195195            0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo);
    196 
     196       
    197197        return eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll);
    198198}
     
    205205 * @return 1 if both floats are equal, 0 otherwise.
    206206 */
    207 int isFloat32eq(float32 a, float32 b)
     207int is_float32_eq(float32 a, float32 b)
    208208{
    209209        /* a equals to b or both are zeros (with any sign) */
    210         return ((a.binary == b.binary) ||
    211             (((a.binary | b.binary) & 0x7FFFFFFF) == 0));
     210        return ((a.bin == b.bin) ||
     211            (((a.bin | b.bin) & 0x7FFFFFFF) == 0));
    212212}
    213213
     
    219219 * @return 1 if both floats are equal, 0 otherwise.
    220220 */
    221 int isFloat64eq(float64 a, float64 b)
     221int is_float64_eq(float64 a, float64 b)
    222222{
    223223        /* a equals to b or both are zeros (with any sign) */
    224         return ((a.binary == b.binary) ||
    225             (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0));
     224        return ((a.bin == b.bin) ||
     225            (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0));
    226226}
    227227
     
    233233 * @return 1 if both floats are equal, 0 otherwise.
    234234 */
    235 int isFloat128eq(float128 a, float128 b)
     235int is_float128_eq(float128 a, float128 b)
    236236{
    237237        uint64_t tmp_hi;
    238238        uint64_t tmp_lo;
    239 
     239       
    240240        /* both are zeros (with any sign) */
    241         or128(a.binary.hi, a.binary.lo,
    242             b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo);
     241        or128(a.bin.hi, a.bin.lo,
     242            b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo);
    243243        and128(tmp_hi, tmp_lo,
    244244            0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo);
     
    246246       
    247247        /* a equals to b */
    248         int are_equal = eq128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo);
    249 
     248        int are_equal = eq128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo);
     249       
    250250        return are_equal || both_zero;
    251251}
     
    258258 * @return 1 if a is lower than b, 0 otherwise.
    259259 */
    260 int isFloat32lt(float32 a, float32 b)
    261 {
    262         if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) {
    263                 return 0; /* +- zeroes */
     260int is_float32_lt(float32 a, float32 b)
     261{
     262        if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) {
     263                /* +- zeroes */
     264                return 0;
    264265        }
    265266       
    266267        if ((a.parts.sign) && (b.parts.sign)) {
    267268                /* if both are negative, smaller is that with greater binary value */
    268                 return (a.binary > b.binary);
    269         }
    270        
    271         /* lets negate signs - now will be positive numbers allways bigger than
    272          * negative (first bit will be set for unsigned integer comparison) */
    273         a.parts.sign = !a.parts.sign;
    274         b.parts.sign = !b.parts.sign;
    275         return (a.binary < b.binary);
     269                return (a.bin > b.bin);
     270        }
     271       
     272        /*
     273         * lets negate signs - now will be positive numbers always
     274         * bigger than negative (first bit will be set for unsigned
     275         * integer comparison)
     276         */
     277        a.parts.sign = !a.parts.sign;
     278        b.parts.sign = !b.parts.sign;
     279        return (a.bin < b.bin);
    276280}
    277281
     
    283287 * @return 1 if a is lower than b, 0 otherwise.
    284288 */
    285 int isFloat64lt(float64 a, float64 b)
    286 {
    287         if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) {
    288                 return 0; /* +- zeroes */
    289         }
    290 
     289int is_float64_lt(float64 a, float64 b)
     290{
     291        if (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0) {
     292                /* +- zeroes */
     293                return 0;
     294        }
     295       
    291296        if ((a.parts.sign) && (b.parts.sign)) {
    292297                /* if both are negative, smaller is that with greater binary value */
    293                 return (a.binary > b.binary);
    294         }
    295 
    296         /* lets negate signs - now will be positive numbers allways bigger than
    297          * negative (first bit will be set for unsigned integer comparison) */
    298         a.parts.sign = !a.parts.sign;
    299         b.parts.sign = !b.parts.sign;
    300         return (a.binary < b.binary);
     298                return (a.bin > b.bin);
     299        }
     300       
     301        /*
     302         * lets negate signs - now will be positive numbers always
     303         * bigger than negative (first bit will be set for unsigned
     304         * integer comparison)
     305         */
     306        a.parts.sign = !a.parts.sign;
     307        b.parts.sign = !b.parts.sign;
     308        return (a.bin < b.bin);
    301309}
    302310
     
    308316 * @return 1 if a is lower than b, 0 otherwise.
    309317 */
    310 int isFloat128lt(float128 a, float128 b)
     318int is_float128_lt(float128 a, float128 b)
    311319{
    312320        uint64_t tmp_hi;
    313321        uint64_t tmp_lo;
    314 
    315         or128(a.binary.hi, a.binary.lo,
    316             b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo);
     322       
     323        or128(a.bin.hi, a.bin.lo,
     324            b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo);
    317325        and128(tmp_hi, tmp_lo,
    318326            0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo);
    319327        if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) {
    320                 return 0; /* +- zeroes */
    321         }
    322 
     328                /* +- zeroes */
     329                return 0;
     330        }
     331       
    323332        if ((a.parts.sign) && (b.parts.sign)) {
    324333                /* if both are negative, smaller is that with greater binary value */
    325                 return lt128(b.binary.hi, b.binary.lo, a.binary.hi, a.binary.lo);
    326         }
    327 
    328         /* lets negate signs - now will be positive numbers allways bigger than
    329          * negative (first bit will be set for unsigned integer comparison) */
    330         a.parts.sign = !a.parts.sign;
    331         b.parts.sign = !b.parts.sign;
    332         return lt128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo);
     334                return lt128(b.bin.hi, b.bin.lo, a.bin.hi, a.bin.lo);
     335        }
     336       
     337        /*
     338         * lets negate signs - now will be positive numbers always
     339         * bigger than negative (first bit will be set for unsigned
     340         * integer comparison)
     341         */
     342        a.parts.sign = !a.parts.sign;
     343        b.parts.sign = !b.parts.sign;
     344        return lt128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo);
    333345}
    334346
     
    340352 * @return 1 if a is greater than b, 0 otherwise.
    341353 */
    342 int isFloat32gt(float32 a, float32 b)
    343 {
    344         if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) {
    345                 return 0; /* zeroes are equal with any sign */
     354int is_float32_gt(float32 a, float32 b)
     355{
     356        if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) {
     357                /* zeroes are equal with any sign */
     358                return 0;
    346359        }
    347360       
    348361        if ((a.parts.sign) && (b.parts.sign)) {
    349362                /* if both are negative, greater is that with smaller binary value */
    350                 return (a.binary < b.binary);
    351         }
    352        
    353         /* lets negate signs - now will be positive numbers allways bigger than
    354          *  negative (first bit will be set for unsigned integer comparison) */
    355         a.parts.sign = !a.parts.sign;
    356         b.parts.sign = !b.parts.sign;
    357         return (a.binary > b.binary);
     363                return (a.bin < b.bin);
     364        }
     365       
     366        /*
     367         * lets negate signs - now will be positive numbers always
     368         * bigger than negative (first bit will be set for unsigned
     369         * integer comparison)
     370         */
     371        a.parts.sign = !a.parts.sign;
     372        b.parts.sign = !b.parts.sign;
     373        return (a.bin > b.bin);
    358374}
    359375
     
    365381 * @return 1 if a is greater than b, 0 otherwise.
    366382 */
    367 int isFloat64gt(float64 a, float64 b)
    368 {
    369         if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) {
    370                 return 0; /* zeroes are equal with any sign */
    371         }
    372 
     383int is_float64_gt(float64 a, float64 b)
     384{
     385        if (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0) {
     386                /* zeroes are equal with any sign */
     387                return 0;
     388        }
     389       
    373390        if ((a.parts.sign) && (b.parts.sign)) {
    374391                /* if both are negative, greater is that with smaller binary value */
    375                 return (a.binary < b.binary);
    376         }
    377 
    378         /* lets negate signs - now will be positive numbers allways bigger than
    379          *  negative (first bit will be set for unsigned integer comparison) */
    380         a.parts.sign = !a.parts.sign;
    381         b.parts.sign = !b.parts.sign;
    382         return (a.binary > b.binary);
     392                return (a.bin < b.bin);
     393        }
     394       
     395        /*
     396         * lets negate signs - now will be positive numbers always
     397         * bigger than negative (first bit will be set for unsigned
     398         * integer comparison)
     399         */
     400        a.parts.sign = !a.parts.sign;
     401        b.parts.sign = !b.parts.sign;
     402        return (a.bin > b.bin);
    383403}
    384404
     
    390410 * @return 1 if a is greater than b, 0 otherwise.
    391411 */
    392 int isFloat128gt(float128 a, float128 b)
     412int is_float128_gt(float128 a, float128 b)
    393413{
    394414        uint64_t tmp_hi;
    395415        uint64_t tmp_lo;
    396 
    397         or128(a.binary.hi, a.binary.lo,
    398             b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo);
     416       
     417        or128(a.bin.hi, a.bin.lo,
     418            b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo);
    399419        and128(tmp_hi, tmp_lo,
    400420            0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo);
    401421        if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) {
    402                 return 0; /* zeroes are equal with any sign */
    403         }
    404 
     422                /* zeroes are equal with any sign */
     423                return 0;
     424        }
     425       
    405426        if ((a.parts.sign) && (b.parts.sign)) {
    406427                /* if both are negative, greater is that with smaller binary value */
    407                 return lt128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo);
    408         }
    409 
    410         /* lets negate signs - now will be positive numbers allways bigger than
    411          *  negative (first bit will be set for unsigned integer comparison) */
    412         a.parts.sign = !a.parts.sign;
    413         b.parts.sign = !b.parts.sign;
    414         return lt128(b.binary.hi, b.binary.lo, a.binary.hi, a.binary.lo);
     428                return lt128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo);
     429        }
     430       
     431        /*
     432         * lets negate signs - now will be positive numbers always
     433         * bigger than negative (first bit will be set for unsigned
     434         * integer comparison)
     435         */
     436        a.parts.sign = !a.parts.sign;
     437        b.parts.sign = !b.parts.sign;
     438        return lt128(b.bin.hi, b.bin.lo, a.bin.hi, a.bin.lo);
    415439}
    416440
Note: See TracChangeset for help on using the changeset viewer.