Changeset 2f08a55d in mainline for arch/ia32/src/fmath.c
- Timestamp:
- 2005-09-03T14:16:25Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f6297e0
- Parents:
- 544b4bf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
arch/ia32/src/fmath.c
r544b4bf r2f08a55d 31 31 32 32 #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 ) 42 34 signed short fmath_get_binary_exponent(double num) 43 35 { … … 78 70 if (exp<0) { 79 71 *intp = 0.0; 80 *intp = fmath_set_sign(0.0L,fmath_is_negative(num));81 72 return num; 82 73 } … … 86 77 *intp=num; 87 78 num=0.0; 88 num= fmath_set_sign(0.0L,fmath_is_negative(*intp));89 79 return num; 90 80 } … … 107 97 }; 108 98 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 }121 99 122 100 double fmath_dpow(double base, double exponent) … … 142 120 } 143 121 122 int 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 136 int 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.