Changeset 2f08a55d in mainline for arch/ia32/src/fmath.c


Ignore:
Timestamp:
2005-09-03T14:16:25Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f6297e0
Parents:
544b4bf
Message:

Support for NaN and infinity in printf.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • arch/ia32/src/fmath.c

    r544b4bf r2f08a55d  
    3131
    3232#define FMATH_MANTISA_MASK ( 0x000fffffffffffffLL )
    33 
    34 int fmath_is_negative(double num)
    35 {
    36         fmath_ld_union_t fmath_ld_union;
    37         fmath_ld_union.bf = num;
    38         return ((fmath_ld_union.ldd[7])&0x80)==0x80; /*first bit is sign, IA32 is little endian -> 8th byte*/
    39 
    40 }
    41 
     33#define FMATH_NAN ( 0x0001000000000001LL )
    4234signed short fmath_get_binary_exponent(double num)
    4335{
     
    7870        if (exp<0) {
    7971                *intp = 0.0;
    80                 *intp = fmath_set_sign(0.0L,fmath_is_negative(num));
    8172                return num;
    8273                }
     
    8677                *intp=num;
    8778                num=0.0;
    88                 num= fmath_set_sign(0.0L,fmath_is_negative(*intp));
    8979                return num;
    9080        }
     
    10797};
    10898       
    109 double fmath_set_sign(double num,__u8 sign)
    110 {
    111         fmath_ld_union_t fmath_ld_union;
    112         fmath_ld_union.bf = num;
    113         fmath_ld_union.ldd[7]=((fmath_ld_union.ldd[7])&0x7f)|(sign<<7); /* change 64th bit (IA32 is a little endian)*/
    114         return fmath_ld_union.bf;
    115 }
    116 
    117 double fmath_abs(double num)
    118 {
    119         return fmath_set_sign(num,0);
    120 }
    12199
    122100double fmath_dpow(double base, double exponent)
     
    142120}
    143121
     122int fmath_is_nan(double num)
     123{
     124        __u16 exp;
     125        fmath_ld_union_t fmath_ld_union;
     126        fmath_ld_union.bf = num;
     127        exp=(((fmath_ld_union.ldd[7])&0x7f)<<4) + (((fmath_ld_union.ldd[6])&0xf0)>>4); /* exponent is 11 bits lenght, so sevent bits is in 8th byte and 4 bits in 7th */
     128
     129        if (exp!=0x07ff) return 0;
     130        if (fmath_get_binary_mantisa(num)>=FMATH_NAN) return 1;
     131       
     132               
     133        return 0;
     134}
     135
     136int fmath_is_infinity(double num)
     137{
     138        __u16 exp;
     139        fmath_ld_union_t fmath_ld_union;
     140        fmath_ld_union.bf = num;
     141        exp=(((fmath_ld_union.ldd[7])&0x7f)<<4) + (((fmath_ld_union.ldd[6])&0xf0)>>4); /* exponent is 11 bits lenght, so sevent bits is in 8th byte and 4 bits in 7th */
     142
     143        if (exp!=0x07ff) return 0;
     144        if (fmath_get_binary_mantisa(num)==0x0) return 1;
     145        return 0;
     146}
Note: See TracChangeset for help on using the changeset viewer.