Ignore:
File:
1 edited

Legend:

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

    r88d5c1e rc67aff2  
    4545 * @return 1 if float is NaN, 0 otherwise.
    4646 */
    47 int is_float32_nan(float32 f)
     47int isFloat32NaN(float32 f)
    4848{
    4949        /* NaN : exp = 0xff and nonzero fraction */
     
    5858 * @return 1 if float is NaN, 0 otherwise.
    5959 */
    60 int is_float64_nan(float64 d)
     60int isFloat64NaN(float64 d)
    6161{
    6262        /* NaN : exp = 0x7ff and nonzero fraction */
     
    7171 * @return 1 if float is NaN, 0 otherwise.
    7272 */
    73 int is_float128_nan(float128 ld)
     73int isFloat128NaN(float128 ld)
    7474{
    7575        /* NaN : exp = 0x7fff and nonzero fraction */
     
    8484 * @return 1 if float is signalling NaN, 0 otherwise.
    8585 */
    86 int is_float32_signan(float32 f)
     86int isFloat32SigNaN(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 is_float64_signan(float64 d)
     100int isFloat64SigNaN(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 is_float128_signan(float128 ld)
     114int isFloat128SigNaN(float128 ld)
    115115{
    116116        /* SigNaN : exp = 0x7fff and fraction = 0xxxxx..x (binary),
     
    128128 * @return 1 if float is infinite, 0 otherwise.
    129129 */
    130 int is_float32_infinity(float32 f)
     130int isFloat32Infinity(float32 f)
    131131{
    132132        /* NaN : exp = 0x7ff and zero fraction */
     
    140140 * @return 1 if float is infinite, 0 otherwise.
    141141 */
    142 int is_float64_infinity(float64 d)
     142int isFloat64Infinity(float64 d)
    143143{
    144144        /* NaN : exp = 0x7ff and zero fraction */
     
    152152 * @return 1 if float is infinite, 0 otherwise.
    153153 */
    154 int is_float128_infinity(float128 ld)
     154int isFloat128Infinity(float128 ld)
    155155{
    156156        /* NaN : exp = 0x7fff and zero fraction */
     
    165165 * @return 1 if float is zero, 0 otherwise.
    166166 */
    167 int is_float32_zero(float32 f)
    168 {
    169         return (((f.bin) & 0x7FFFFFFF) == 0);
     167int isFloat32Zero(float32 f)
     168{
     169        return (((f.binary) & 0x7FFFFFFF) == 0);
    170170}
    171171
     
    176176 * @return 1 if float is zero, 0 otherwise.
    177177 */
    178 int is_float64_zero(float64 d)
    179 {
    180         return (((d.bin) & 0x7FFFFFFFFFFFFFFFll) == 0);
     178int isFloat64Zero(float64 d)
     179{
     180        return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0);
    181181}
    182182
     
    187187 * @return 1 if float is zero, 0 otherwise.
    188188 */
    189 int is_float128_zero(float128 ld)
     189int isFloat128Zero(float128 ld)
    190190{
    191191        uint64_t tmp_hi;
    192192        uint64_t tmp_lo;
    193        
    194         and128(ld.bin.hi, ld.bin.lo,
     193
     194        and128(ld.binary.hi, ld.binary.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 is_float32_eq(float32 a, float32 b)
     207int isFloat32eq(float32 a, float32 b)
    208208{
    209209        /* a equals to b or both are zeros (with any sign) */
    210         return ((a.bin == b.bin) ||
    211             (((a.bin | b.bin) & 0x7FFFFFFF) == 0));
     210        return ((a.binary == b.binary) ||
     211            (((a.binary | b.binary) & 0x7FFFFFFF) == 0));
    212212}
    213213
     
    219219 * @return 1 if both floats are equal, 0 otherwise.
    220220 */
    221 int is_float64_eq(float64 a, float64 b)
     221int isFloat64eq(float64 a, float64 b)
    222222{
    223223        /* a equals to b or both are zeros (with any sign) */
    224         return ((a.bin == b.bin) ||
    225             (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0));
     224        return ((a.binary == b.binary) ||
     225            (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0));
    226226}
    227227
     
    233233 * @return 1 if both floats are equal, 0 otherwise.
    234234 */
    235 int is_float128_eq(float128 a, float128 b)
     235int isFloat128eq(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.bin.hi, a.bin.lo,
    242             b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo);
     241        or128(a.binary.hi, a.binary.lo,
     242            b.binary.hi, b.binary.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.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo);
    249        
     248        int are_equal = eq128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo);
     249
    250250        return are_equal || both_zero;
    251251}
     
    258258 * @return 1 if a is lower than b, 0 otherwise.
    259259 */
    260 int is_float32_lt(float32 a, float32 b)
    261 {
    262         if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) {
    263                 /* +- zeroes */
    264                 return 0;
     260int isFloat32lt(float32 a, float32 b)
     261{
     262        if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) {
     263                return 0; /* +- zeroes */
    265264        }
    266265       
    267266        if ((a.parts.sign) && (b.parts.sign)) {
    268267                /* if both are negative, smaller is that with greater binary value */
    269                 return (a.bin > b.bin);
     268                return (a.binary > b.binary);
    270269        }
    271270       
    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);
     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);
    280276}
    281277
     
    287283 * @return 1 if a is lower than b, 0 otherwise.
    288284 */
    289 int is_float64_lt(float64 a, float64 b)
    290 {
    291         if (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0) {
    292                 /* +- zeroes */
    293                 return 0;
    294         }
    295        
     285int isFloat64lt(float64 a, float64 b)
     286{
     287        if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) {
     288                return 0; /* +- zeroes */
     289        }
     290
    296291        if ((a.parts.sign) && (b.parts.sign)) {
    297292                /* if both are negative, smaller is that with greater binary value */
    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);
     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);
    309301}
    310302
     
    316308 * @return 1 if a is lower than b, 0 otherwise.
    317309 */
    318 int is_float128_lt(float128 a, float128 b)
     310int isFloat128lt(float128 a, float128 b)
    319311{
    320312        uint64_t tmp_hi;
    321313        uint64_t tmp_lo;
    322        
    323         or128(a.bin.hi, a.bin.lo,
    324             b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo);
     314
     315        or128(a.binary.hi, a.binary.lo,
     316            b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo);
    325317        and128(tmp_hi, tmp_lo,
    326318            0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo);
    327319        if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) {
    328                 /* +- zeroes */
    329                 return 0;
    330         }
    331        
     320                return 0; /* +- zeroes */
     321        }
     322
    332323        if ((a.parts.sign) && (b.parts.sign)) {
    333324                /* if both are negative, smaller is that with greater binary value */
    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);
     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);
    345333}
    346334
     
    352340 * @return 1 if a is greater than b, 0 otherwise.
    353341 */
    354 int 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;
     342int isFloat32gt(float32 a, float32 b)
     343{
     344        if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) {
     345                return 0; /* zeroes are equal with any sign */
    359346        }
    360347       
    361348        if ((a.parts.sign) && (b.parts.sign)) {
    362349                /* if both are negative, greater is that with smaller binary value */
    363                 return (a.bin < b.bin);
     350                return (a.binary < b.binary);
    364351        }
    365352       
    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);
     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);
    374358}
    375359
     
    381365 * @return 1 if a is greater than b, 0 otherwise.
    382366 */
    383 int 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        
     367int 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
    390373        if ((a.parts.sign) && (b.parts.sign)) {
    391374                /* if both are negative, greater is that with smaller binary value */
    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);
     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);
    403383}
    404384
     
    410390 * @return 1 if a is greater than b, 0 otherwise.
    411391 */
    412 int is_float128_gt(float128 a, float128 b)
     392int isFloat128gt(float128 a, float128 b)
    413393{
    414394        uint64_t tmp_hi;
    415395        uint64_t tmp_lo;
    416        
    417         or128(a.bin.hi, a.bin.lo,
    418             b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo);
     396
     397        or128(a.binary.hi, a.binary.lo,
     398            b.binary.hi, b.binary.lo, &tmp_hi, &tmp_lo);
    419399        and128(tmp_hi, tmp_lo,
    420400            0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo);
    421401        if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) {
    422                 /* zeroes are equal with any sign */
    423                 return 0;
    424         }
    425        
     402                return 0; /* zeroes are equal with any sign */
     403        }
     404
    426405        if ((a.parts.sign) && (b.parts.sign)) {
    427406                /* if both are negative, greater is that with smaller binary value */
    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);
     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);
    439415}
    440416
Note: See TracChangeset for help on using the changeset viewer.