Changeset 2f08a55d in mainline


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.

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/include/fmath.h

    r544b4bf r2f08a55d  
    3535typedef union { double bf; unsigned char ldd[8]; }  fmath_ld_union_t;
    3636
    37 int fmath_is_negative(double num);
    38 //int fmath_is_exponent_negative(double num);
    39 
    4037/**returns exponent in binary encoding*/
    4138signed short fmath_get_binary_exponent(double num);
     
    5451double fmath_fint(double num, double *intp);
    5552
    56 /** Return absolute value from num */
    57 double fmath_abs(double num);
    58 
    59 double fmath_set_sign(double num,__u8 sign);
    60 
    6153/** count base^exponent from positive exponent
    6254* @param base
     
    6658double fmath_dpow(double base, double exponent) ;
    6759
     60/** return 1, if num is NaN */
     61int fmath_is_nan(double num);
     62
     63/** return 1, if fmath is a infinity */
     64int fmath_is_infinity(double num);
  • arch/amd64/src/fmath.c

    r544b4bf r2f08a55d  
    3232        //TODO:
    3333#define FMATH_MANTISA_MASK ( 0x000fffffffffffffLL )
    34 
    35 int fmath_is_negative(double num)
    36 {       //TODO:
    37 /*      fmath_ld_union_t fmath_ld_union;
    38         fmath_ld_union.bf = num;
    39         return ((fmath_ld_union.ldd[7])&0x80)==0x80; //first bit is sign, IA32 is little endian -> 8th byte
    40 */
    41         return 0;
    42 }
    4334
    4435signed short fmath_get_binary_exponent(double num)
     
    117108};
    118109       
    119 double fmath_set_sign(double num,__u8 sign)
    120 {       //TODO:
    121 /*      fmath_ld_union_t fmath_ld_union;
    122         fmath_ld_union.bf = num;
    123         fmath_ld_union.ldd[7]=((fmath_ld_union.ldd[7])&0x7f)|(sign<<7); // change 64th bit (IA32 is a little endian)
    124         return fmath_ld_union.bf;
    125 */      return 1.0;
    126 }
    127 
    128 double fmath_abs(double num)
    129 {       //TODO:
    130 /*
    131         return fmath_set_sign(num,0);
    132 */
    133         return 1.0;
    134 }
    135110
    136111double fmath_dpow(double base, double exponent)
     
    158133}
    159134
     135
     136int fmath_is_nan(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)>=FMATH_NAN) return 1;
     145       
     146*/             
     147        return 0;
     148}
     149
     150int fmath_is_infinity(double num)
     151{
     152/*      __u16 exp;
     153        fmath_ld_union_t fmath_ld_union;
     154        fmath_ld_union.bf = num;
     155        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
     156
     157        if (exp!=0x07ff) return 0;
     158        if (fmath_get_binary_mantisa(num)==0x0) return 1;
     159*/      return 0;
     160}
     161
  • arch/ia32/include/fmath.h

    r544b4bf r2f08a55d  
    3535typedef union { double bf; unsigned char ldd[8]; }  fmath_ld_union_t;
    3636
    37 int fmath_is_negative(double num);
    38 //int fmath_is_exponent_negative(double num);
    39 
    4037/**returns exponent in binary encoding*/
    4138signed short fmath_get_binary_exponent(double num);
     
    5451double fmath_fint(double num, double *intp);
    5552
    56 /** Return absolute value from num */
    57 double fmath_abs(double num);
    58 
    59 double fmath_set_sign(double num,__u8 sign);
    60 
    6153/** count base^exponent from positive exponent
    6254* @param base
     
    6658double fmath_dpow(double base, double exponent) ;
    6759
     60/** return 1, if num is NaN */
     61int fmath_is_nan(double num);
     62
     63/** return 1, if fmath is a infinity */
     64int fmath_is_infinity(double num);
  • 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}
  • arch/ia64/include/fmath.h

    r544b4bf r2f08a55d  
    3535typedef union { double bf; unsigned char ldd[8]; }  fmath_ld_union_t;
    3636
    37 int fmath_is_negative(double num);
    38 //int fmath_is_exponent_negative(double num);
    39 
    4037/**returns exponent in binary encoding*/
    4138signed short fmath_get_binary_exponent(double num);
     
    5451double fmath_fint(double num, double *intp);
    5552
    56 /** Return absolute value from num */
    57 double fmath_abs(double num);
    58 
    59 double fmath_set_sign(double num,__u8 sign);
    60 
    6153/** count base^exponent from positive exponent
    6254* @param base
     
    6658double fmath_dpow(double base, double exponent) ;
    6759
     60/** return 1, if num is NaN */
     61int fmath_is_nan(double num);
     62
     63/** return 1, if fmath is a infinity */
     64int fmath_is_infinity(double num);
  • arch/ia64/src/fmath.c

    r544b4bf r2f08a55d  
    3232        //TODO:
    3333#define FMATH_MANTISA_MASK ( 0x000fffffffffffffLL )
    34 
    35 int fmath_is_negative(double num)
    36 {       //TODO:
    37 /*      fmath_ld_union_t fmath_ld_union;
    38         fmath_ld_union.bf = num;
    39         return ((fmath_ld_union.ldd[7])&0x80)==0x80; //first bit is sign, IA32 is little endian -> 8th byte
    40 */
    41         return 0;
    42 }
    4334
    4435signed short fmath_get_binary_exponent(double num)
     
    117108};
    118109       
    119 double fmath_set_sign(double num,__u8 sign)
    120 {       //TODO:
    121 /*      fmath_ld_union_t fmath_ld_union;
    122         fmath_ld_union.bf = num;
    123         fmath_ld_union.ldd[7]=((fmath_ld_union.ldd[7])&0x7f)|(sign<<7); // change 64th bit (IA32 is a little endian)
    124         return fmath_ld_union.bf;
    125 */      return 1.0;
    126 }
    127 
    128 double fmath_abs(double num)
    129 {       //TODO:
    130 /*
    131         return fmath_set_sign(num,0);
    132 */
    133         return 1.0;
    134 }
    135110
    136111double fmath_dpow(double base, double exponent)
     
    158133}
    159134
     135
     136int fmath_is_nan(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)>=FMATH_NAN) return 1;
     145       
     146*/             
     147        return 0;
     148}
     149
     150int fmath_is_infinity(double num)
     151{
     152/*      __u16 exp;
     153        fmath_ld_union_t fmath_ld_union;
     154        fmath_ld_union.bf = num;
     155        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
     156
     157        if (exp!=0x07ff) return 0;
     158        if (fmath_get_binary_mantisa(num)==0x0) return 1;
     159*/      return 0;
     160}
     161
  • arch/mips/include/fmath.h

    r544b4bf r2f08a55d  
    3535typedef union { double bf; unsigned char ldd[8]; }  fmath_ld_union_t;
    3636
    37 int fmath_is_negative(double num);
    38 //int fmath_is_exponent_negative(double num);
    39 
    4037/**returns exponent in binary encoding*/
    4138signed short fmath_get_binary_exponent(double num);
     
    5451double fmath_fint(double num, double *intp);
    5552
    56 /** Return absolute value from num */
    57 double fmath_abs(double num);
    58 
    59 double fmath_set_sign(double num,__u8 sign);
    60 
    6153/** count base^exponent from positive exponent
    6254* @param base
     
    6658double fmath_dpow(double base, double exponent) ;
    6759
     60/** return 1, if num is NaN */
     61int fmath_is_nan(double num);
     62
     63/** return 1, if fmath is a infinity */
     64int fmath_is_infinity(double num);
  • arch/mips/src/fmath.c

    r544b4bf r2f08a55d  
    3232        //TODO:
    3333#define FMATH_MANTISA_MASK ( 0x000fffffffffffffLL )
    34 
    35 int fmath_is_negative(double num)
    36 {       //TODO:
    37 /*      fmath_ld_union_t fmath_ld_union;
    38         fmath_ld_union.bf = num;
    39         return ((fmath_ld_union.ldd[7])&0x80)==0x80; //first bit is sign, IA32 is little endian -> 8th byte
    40 */
    41         return 0;
    42 }
    4334
    4435signed short fmath_get_binary_exponent(double num)
     
    117108};
    118109       
    119 double fmath_set_sign(double num,__u8 sign)
    120 {       //TODO:
    121 /*      fmath_ld_union_t fmath_ld_union;
    122         fmath_ld_union.bf = num;
    123         fmath_ld_union.ldd[7]=((fmath_ld_union.ldd[7])&0x7f)|(sign<<7); // change 64th bit (IA32 is a little endian)
    124         return fmath_ld_union.bf;
    125 */      return 1.0;
    126 }
    127 
    128 double fmath_abs(double num)
    129 {       //TODO:
    130 /*
    131         return fmath_set_sign(num,0);
    132 */
    133         return 1.0;
    134 }
    135110
    136111double fmath_dpow(double base, double exponent)
     
    158133}
    159134
     135
     136int fmath_is_nan(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)>=FMATH_NAN) return 1;
     145       
     146*/             
     147        return 0;
     148}
     149
     150int fmath_is_infinity(double num)
     151{
     152/*      __u16 exp;
     153        fmath_ld_union_t fmath_ld_union;
     154        fmath_ld_union.bf = num;
     155        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
     156
     157        if (exp!=0x07ff) return 0;
     158        if (fmath_get_binary_mantisa(num)==0x0) return 1;
     159*/      return 0;
     160}
     161
  • arch/ppc/include/fmath.h

    r544b4bf r2f08a55d  
    3535typedef union { double bf; unsigned char ldd[8]; }  fmath_ld_union_t;
    3636
    37 int fmath_is_negative(double num);
    38 //int fmath_is_exponent_negative(double num);
    39 
    4037/**returns exponent in binary encoding*/
    4138signed short fmath_get_binary_exponent(double num);
     
    5451double fmath_fint(double num, double *intp);
    5552
    56 /** Return absolute value from num */
    57 double fmath_abs(double num);
    58 
    59 double fmath_set_sign(double num,__u8 sign);
    60 
    6153/** count base^exponent from positive exponent
    6254* @param base
     
    6658double fmath_dpow(double base, double exponent) ;
    6759
     60/** return 1, if num is NaN */
     61int fmath_is_nan(double num);
     62
     63/** return 1, if fmath is a infinity */
     64int fmath_is_infinity(double num);
  • arch/ppc/src/fmath.c

    r544b4bf r2f08a55d  
    3232        //TODO:
    3333#define FMATH_MANTISA_MASK ( 0x000fffffffffffffLL )
    34 
    35 int fmath_is_negative(double num)
    36 {       //TODO:
    37 /*      fmath_ld_union_t fmath_ld_union;
    38         fmath_ld_union.bf = num;
    39         return ((fmath_ld_union.ldd[7])&0x80)==0x80; //first bit is sign, IA32 is little endian -> 8th byte
    40 */
    41         return 0;
    42 }
    4334
    4435signed short fmath_get_binary_exponent(double num)
     
    117108};
    118109       
    119 double fmath_set_sign(double num,__u8 sign)
    120 {       //TODO:
    121 /*      fmath_ld_union_t fmath_ld_union;
    122         fmath_ld_union.bf = num;
    123         fmath_ld_union.ldd[7]=((fmath_ld_union.ldd[7])&0x7f)|(sign<<7); // change 64th bit (IA32 is a little endian)
    124         return fmath_ld_union.bf;
    125 */      return 1.0;
    126 }
    127 
    128 double fmath_abs(double num)
    129 {       //TODO:
    130 /*
    131         return fmath_set_sign(num,0);
    132 */
    133         return 1.0;
    134 }
    135110
    136111double fmath_dpow(double base, double exponent)
     
    158133}
    159134
     135
     136int fmath_is_nan(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)>=FMATH_NAN) return 1;
     145       
     146*/             
     147        return 0;
     148}
     149
     150int fmath_is_infinity(double num)
     151{
     152/*      __u16 exp;
     153        fmath_ld_union_t fmath_ld_union;
     154        fmath_ld_union.bf = num;
     155        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
     156
     157        if (exp!=0x07ff) return 0;
     158        if (fmath_get_binary_mantisa(num)==0x0) return 1;
     159*/      return 0;
     160}
     161
  • src/debug/print.c

    r544b4bf r2f08a55d  
    5050        unsigned long in1,in2; 
    5151       
    52         /*
     52
    5353        if (fmath_is_nan(num)) {
    5454                print_str("NaN");
    5555                return;
    5656        }
    57         */
    58        
    59         if (fmath_is_negative(num)) {
     57       
     58        if (num<0.0) {
    6059                putchar('-');
    61                 }
    62        
    63         num=fmath_abs(num);
     60                num=num*-1.0;
     61                }
     62
     63
     64        if (fmath_is_infinity(num)) {
     65                print_str("Inf");
     66                return;
     67                }
    6468
    6569        if ((modifier=='E')||(modifier=='e')) {
     
    7983                }
    8084               
    81 
    82         /*
    83         if (fmath_is_infinity(num)) {
    84                 print_str("Inf");
    85                 }
    86         */
    8785        //TODO: rounding constant - when we got fraction >= 0.5, we must increment last printed number
    8886
  • test/print/print1/test.c

    r544b4bf r2f08a55d  
    3232{
    3333        __u64 u64const = 0x0123456789ABCDEFLL;
     34        double d;
    3435        printf(" Printf test \n");
    3536        printf(" Q  %Q  %q \n",u64const, u64const);
     
    4849        printf(" E  %.10E %.8e (123456789.987654321e12 for precision 10 & 8)\n",123456789.987654321e12,123456789.987654321e12);
    4950        printf(" E  %.10E %.8e (987654321.123456789e12 for precision 10 & 8)\n",987654321.123456789e12,987654321.123456789e12);
     51        u64const =0x7fffffffffffffffLL;
     52        d =*((double *)((void *)(&u64const)));
     53        printf(" E  %.10E (NaN)\n",d);
     54        u64const =(0xfff0000000000000LL);
     55        d =*(double *)(void *)(&u64const);
     56        printf(" E  %.10E (-Inf)\n",d);
    5057        return;
    5158}
Note: See TracChangeset for help on using the changeset viewer.