Changeset 6219 in orxonox.OLD for branches/network/src/lib/network/converter.cc
- Timestamp:
- Dec 21, 2005, 1:39:20 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/converter.cc
r6197 r6219 54 54 { 55 55 const int mod = 256; // = 2^8 56 57 56 57 58 58 byte* result = new byte[INTSIZE]; 59 59 int sgn; … … 65 65 x = -x; 66 66 } 67 67 68 68 for (int i = 0; i < INTSIZE; i++) 69 69 { … … 71 71 x /= mod; 72 72 } 73 73 74 74 if (sgn == -1) 75 75 result[INTSIZE - 1] += sgnadd; 76 77 76 77 78 78 return result; 79 79 } … … 84 84 * @return: An int that accords the given byte-array 85 85 */ 86 int Converter::byteArrayToInt( byte* a)86 int Converter::byteArrayToInt(const byte* a) 87 87 { 88 88 int mult = 1; … … 102 102 else 103 103 result += a[INTSIZE - 1] * mult; 104 104 105 105 return result; 106 106 } … … 113 113 char* result = new char[200]; 114 114 int pos = 0; 115 115 116 116 if (x < 0) 117 117 { … … 119 119 x = -x; 120 120 } 121 121 122 122 float sub = 1; 123 123 while (sub < x) … … 135 135 pos++; 136 136 sub /= 2; 137 137 138 138 if (sub == 0.5f) 139 139 result[pos++] = '.'; 140 140 } 141 141 142 142 return result; 143 143 } … … 154 154 int mantisse = 0; 155 155 int exponent = 128; 156 156 157 157 int sgn; 158 158 if (x < 0) … … 163 163 else 164 164 sgn = 1; 165 165 166 166 float sub = 1; 167 167 while (sub < x) … … 178 178 x -= sub; 179 179 } 180 180 181 181 mantisse *= 2; 182 182 exponent--; … … 190 190 exponent--; 191 191 } 192 193 //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 194 192 193 //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 194 195 195 mantisse -= expmult; 196 196 197 197 int hx = mantisse + expmult * exponent; 198 198 byte* result = intToByteArray(hx); 199 199 if (sgn == -1) 200 200 result[3] += sgnadd; 201 201 202 202 return result; 203 203 } … … 214 214 int mantisse = hmant % expmult; 215 215 mantisse += expmult; 216 216 217 217 int hexp = a[2] + a[3] * 256; 218 218 int exponent = (hexp / 128) % 256 - 128; 219 219 220 220 int sgn; 221 221 if (a[3] >= sgnadd) … … 223 223 else 224 224 sgn = 1; 225 225 226 226 //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 227 227 228 228 float emult = 1; 229 229 if (exponent > 0) … … 233 233 for (int i = 0; i > exponent; i--) 234 234 emult /= 2; 235 235 236 236 float result = mantisse * emult; 237 237 if (sgn == -1) 238 238 result = -result; 239 239 240 240 return result; 241 241 }
Note: See TracChangeset
for help on using the changeset viewer.