Changeset 750636a in mainline for uspace/lib/softfloat/generic/comparison.c
- Timestamp:
- 2011-05-06T14:21:25Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7b90778d, b5e68c8
- Parents:
- 042fbe0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/generic/comparison.c
r042fbe0 r750636a 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #include <sftypes.h>36 #include <comparison.h>35 #include <sftypes.h> 36 #include <comparison.h> 37 37 38 inline int isFloat32NaN(float32 f) 39 { /* NaN : exp = 0xff and nonzero fraction */ 40 return ((f.parts.exp==0xFF)&&(f.parts.fraction)); 38 /* NaN : exp = 0xff and nonzero fraction */ 39 int isFloat32NaN(float32 f) 40 { 41 return ((f.parts.exp == 0xFF) && (f.parts.fraction)); 41 42 } 42 43 43 inline int isFloat64NaN(float64 d) 44 { /* NaN : exp = 0x7ff and nonzero fraction */ 45 return ((d.parts.exp==0x7FF)&&(d.parts.fraction)); 44 /* NaN : exp = 0x7ff and nonzero fraction */ 45 int isFloat64NaN(float64 d) 46 { 47 return ((d.parts.exp == 0x7FF) && (d.parts.fraction)); 46 48 } 47 49 48 inline int isFloat32SigNaN(float32 f) 49 { /* SigNaN : exp = 0xff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 50 return ((f.parts.exp==0xFF)&&(f.parts.fraction<0x400000)&&(f.parts.fraction)); 50 /* SigNaN : exp = 0xff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 51 int isFloat32SigNaN(float32 f) 52 { 53 return ((f.parts.exp == 0xFF) && (f.parts.fraction < 0x400000) && (f.parts.fraction)); 51 54 } 52 55 53 inline int isFloat64SigNaN(float64 d) 54 { /* SigNaN : exp = 0x7ff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 55 return ((d.parts.exp==0x7FF)&&(d.parts.fraction)&&(d.parts.fraction<0x8000000000000ll)); 56 /* SigNaN : exp = 0x7ff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 57 int isFloat64SigNaN(float64 d) 58 { 59 return ((d.parts.exp == 0x7FF) && (d.parts.fraction) && (d.parts.fraction < 0x8000000000000ll)); 56 60 } 57 61 58 in line int isFloat32Infinity(float32 f)62 int isFloat32Infinity(float32 f) 59 63 { 60 return ((f.parts.exp ==0xFF)&&(f.parts.fraction==0x0));64 return ((f.parts.exp == 0xFF) && (f.parts.fraction == 0x0)); 61 65 } 62 66 63 in line int isFloat64Infinity(float64 d)67 int isFloat64Infinity(float64 d) 64 68 { 65 return ((d.parts.exp ==0x7FF)&&(d.parts.fraction==0x0));69 return ((d.parts.exp == 0x7FF) && (d.parts.fraction == 0x0)); 66 70 } 67 71 68 in line int isFloat32Zero(float32 f)72 int isFloat32Zero(float32 f) 69 73 { 70 74 return (((f.binary) & 0x7FFFFFFF) == 0); 71 75 } 72 76 73 in line int isFloat64Zero(float64 d)77 int isFloat64Zero(float64 d) 74 78 { 75 79 return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0); … … 77 81 78 82 /** 79 * @return 1 , if both floats are equal - but NaNs are not recognized83 * @return 1 if both floats are equal - but NaNs are not recognized 80 84 */ 81 in line int isFloat32eq(float32 a, float32 b)85 int isFloat32eq(float32 a, float32 b) 82 86 { 83 return ((a.binary==b.binary)||(((a.binary| b.binary)&0x7FFFFFFF)==0)); /* a equals to b or both are zeros (with any sign) */ 87 /* a equals to b or both are zeros (with any sign) */ 88 return ((a.binary==b.binary) || (((a.binary | b.binary) & 0x7FFFFFFF) == 0)); 84 89 } 85 90 86 91 /** 87 * @return 1 , if a<b - but NaNs are not recognized92 * @return 1 if a < b - but NaNs are not recognized 88 93 */ 89 in line int isFloat32lt(float32 a, float32 b)94 int isFloat32lt(float32 a, float32 b) 90 95 { 91 if (((a.binary | b.binary)&0x7FFFFFFF)==0) {96 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) 92 97 return 0; /* +- zeroes */ 93 };94 98 95 if ((a.parts.sign)&&(b.parts.sign)) { 96 /*if both are negative, smaller is that with greater binary value*/ 97 return (a.binary>b.binary); 98 }; 99 if ((a.parts.sign) && (b.parts.sign)) 100 /* if both are negative, smaller is that with greater binary value */ 101 return (a.binary > b.binary); 99 102 100 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/ 101 a.parts.sign=!a.parts.sign; 102 b.parts.sign=!b.parts.sign; 103 return (a.binary<b.binary); 104 103 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison) */ 104 a.parts.sign = !a.parts.sign; 105 b.parts.sign = !b.parts.sign; 106 return (a.binary < b.binary); 105 107 } 106 108 107 109 /** 108 * @return 1 , if a>b - but NaNs are not recognized110 * @return 1 if a > b - but NaNs are not recognized 109 111 */ 110 in line int isFloat32gt(float32 a, float32 b)112 int isFloat32gt(float32 a, float32 b) 111 113 { 112 if (((a.binary | b.binary)&0x7FFFFFFF)==0) {114 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) 113 115 return 0; /* zeroes are equal with any sign */ 114 };115 116 116 if ((a.parts.sign)&&(b.parts.sign)) { 117 /*if both are negative, greater is that with smaller binary value*/ 118 return (a.binary<b.binary); 119 }; 117 if ((a.parts.sign) && (b.parts.sign)) 118 /* if both are negative, greater is that with smaller binary value */ 119 return (a.binary < b.binary); 120 120 121 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/ 122 a.parts.sign=!a.parts.sign; 123 b.parts.sign=!b.parts.sign; 124 return (a.binary>b.binary); 125 121 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison) */ 122 a.parts.sign = !a.parts.sign; 123 b.parts.sign = !b.parts.sign; 124 return (a.binary > b.binary); 126 125 } 127 126
Note:
See TracChangeset
for help on using the changeset viewer.