diff options
| author | manuel <manuel@nc8430.lan> | 2009-05-30 13:12:22 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-05-30 13:12:22 +0200 |
| commit | 303c21178a3e28cc8ef3400877d416fd955737e0 (patch) | |
| tree | f8e6decec28e55b1af2a02f6cf058d973acffc61 | |
| parent | d249cc2f9a9086e9aab8f62db34a7a653c213f97 (diff) | |
| download | ooprog-303c21178a3e28cc8ef3400877d416fd955737e0.tar.gz ooprog-303c21178a3e28cc8ef3400877d416fd955737e0.tar.bz2 ooprog-303c21178a3e28cc8ef3400877d416fd955737e0.zip | |
cdatn fix
| -rw-r--r-- | ue4/mycpu/cdatn.h | 53 | ||||
| -rw-r--r-- | ue4/mycpu/mycpu.cpp | 2 |
2 files changed, 17 insertions, 38 deletions
diff --git a/ue4/mycpu/cdatn.h b/ue4/mycpu/cdatn.h index cd6573a..4e68f0b 100644 --- a/ue4/mycpu/cdatn.h +++ b/ue4/mycpu/cdatn.h | |||
| @@ -68,13 +68,16 @@ class CDatN | |||
| 68 | * @param width maximum width | 68 | * @param width maximum width |
| 69 | * @return - | 69 | * @return - |
| 70 | * @globalvars none | 70 | * @globalvars none |
| 71 | * @exception none | 71 | * @exception std::runtime_error |
| 72 | * @pre none | 72 | * @pre none |
| 73 | * @post none | 73 | * @post none |
| 74 | */ | 74 | */ |
| 75 | CDatN(const int newval, unsigned width = 31) | 75 | CDatN(const int newval, unsigned width = 31) |
| 76 | : m_value(((1 << width) - 1) & newval), m_width(width) | 76 | : m_value(((1 << width) - 1) & newval), m_width(width) |
| 77 | {} | 77 | { |
| 78 | if (width < 2 || width > 32) | ||
| 79 | throw std::runtime_error("width must be between 2 and 32"); | ||
| 80 | } | ||
| 78 | 81 | ||
| 79 | /** | 82 | /** |
| 80 | * @method getValue | 83 | * @method getValue |
| @@ -148,8 +151,7 @@ class CDatN | |||
| 148 | */ | 151 | */ |
| 149 | CDatN &operator=(const int& newval) | 152 | CDatN &operator=(const int& newval) |
| 150 | { | 153 | { |
| 151 | m_value = newval; | 154 | m_value = ((1 << m_width) - 1) & newval; |
| 152 | align(); | ||
| 153 | return *this; | 155 | return *this; |
| 154 | } | 156 | } |
| 155 | 157 | ||
| @@ -165,8 +167,7 @@ class CDatN | |||
| 165 | */ | 167 | */ |
| 166 | CDatN& operator+=(const CDatN& x) | 168 | CDatN& operator+=(const CDatN& x) |
| 167 | { | 169 | { |
| 168 | m_value += x.m_value; | 170 | m_value = ((1 << m_width) - 1) & (m_value + x.m_value); |
| 169 | align(); | ||
| 170 | return *this; | 171 | return *this; |
| 171 | } | 172 | } |
| 172 | 173 | ||
| @@ -182,8 +183,7 @@ class CDatN | |||
| 182 | */ | 183 | */ |
| 183 | CDatN& operator-=(const CDatN& x) | 184 | CDatN& operator-=(const CDatN& x) |
| 184 | { | 185 | { |
| 185 | m_value -= x.m_value; | 186 | m_value = ((1 << m_width) - 1) & (m_value - x.m_value); |
| 186 | align(); | ||
| 187 | return *this; | 187 | return *this; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| @@ -199,8 +199,7 @@ class CDatN | |||
| 199 | */ | 199 | */ |
| 200 | CDatN& operator*=(const CDatN& x) | 200 | CDatN& operator*=(const CDatN& x) |
| 201 | { | 201 | { |
| 202 | m_value *= x.m_value; | 202 | m_value = ((1 << m_width) - 1) & (m_value * x.m_value); |
| 203 | align(); | ||
| 204 | return *this; | 203 | return *this; |
| 205 | } | 204 | } |
| 206 | 205 | ||
| @@ -216,8 +215,7 @@ class CDatN | |||
| 216 | */ | 215 | */ |
| 217 | CDatN& operator/=(const CDatN& x) | 216 | CDatN& operator/=(const CDatN& x) |
| 218 | { | 217 | { |
| 219 | m_value /= x.m_value; | 218 | m_value = ((1 << m_width) - 1) & (m_value / x.m_value); |
| 220 | align(); | ||
| 221 | return *this; | 219 | return *this; |
| 222 | } | 220 | } |
| 223 | 221 | ||
| @@ -233,8 +231,7 @@ class CDatN | |||
| 233 | */ | 231 | */ |
| 234 | CDatN& operator%=(const CDatN& x) | 232 | CDatN& operator%=(const CDatN& x) |
| 235 | { | 233 | { |
| 236 | m_value %= x.m_value; | 234 | m_value = ((1 << m_width) - 1) & (m_value % x.m_value); |
| 237 | align(); | ||
| 238 | return *this; | 235 | return *this; |
| 239 | } | 236 | } |
| 240 | 237 | ||
| @@ -250,8 +247,7 @@ class CDatN | |||
| 250 | */ | 247 | */ |
| 251 | CDatN& operator|=(const CDatN& x) | 248 | CDatN& operator|=(const CDatN& x) |
| 252 | { | 249 | { |
| 253 | m_value |= x.m_value; | 250 | m_value = ((1 << m_width) - 1) & (m_value | x.m_value); |
| 254 | align(); | ||
| 255 | return *this; | 251 | return *this; |
| 256 | } | 252 | } |
| 257 | 253 | ||
| @@ -267,8 +263,7 @@ class CDatN | |||
| 267 | */ | 263 | */ |
| 268 | CDatN& operator&=(const CDatN& x) | 264 | CDatN& operator&=(const CDatN& x) |
| 269 | { | 265 | { |
| 270 | m_value &= x.m_value; | 266 | m_value = ((1 << m_width) - 1) & (m_value & x.m_value); |
| 271 | align(); | ||
| 272 | return *this; | 267 | return *this; |
| 273 | } | 268 | } |
| 274 | 269 | ||
| @@ -284,8 +279,7 @@ class CDatN | |||
| 284 | */ | 279 | */ |
| 285 | CDatN& operator^=(const CDatN& x) | 280 | CDatN& operator^=(const CDatN& x) |
| 286 | { | 281 | { |
| 287 | m_value ^= x.m_value; | 282 | m_value = ((1 << m_width) - 1) & (m_value ^ x.m_value); |
| 288 | align(); | ||
| 289 | return *this; | 283 | return *this; |
| 290 | } | 284 | } |
| 291 | 285 | ||
| @@ -301,8 +295,7 @@ class CDatN | |||
| 301 | */ | 295 | */ |
| 302 | CDatN& operator++() | 296 | CDatN& operator++() |
| 303 | { | 297 | { |
| 304 | m_value++; | 298 | m_value = ((1 << m_width) - 1) & (m_value + 1); |
| 305 | align(); | ||
| 306 | return *this; | 299 | return *this; |
| 307 | } | 300 | } |
| 308 | 301 | ||
| @@ -353,25 +346,11 @@ class CDatN | |||
| 353 | friend std::istream& operator>>(std::istream & stream, CDatN& cdat) | 346 | friend std::istream& operator>>(std::istream & stream, CDatN& cdat) |
| 354 | { | 347 | { |
| 355 | stream >> cdat.m_value; | 348 | stream >> cdat.m_value; |
| 356 | cdat.align(); | 349 | cdat.m_value = ((1 << cdat.m_width) - 1) & cdat.m_value; |
| 357 | return stream; | 350 | return stream; |
| 358 | } | 351 | } |
| 359 | 352 | ||
| 360 | protected: | 353 | protected: |
| 361 | /** | ||
| 362 | * @method align | ||
| 363 | * @brief aligns value by width | ||
| 364 | * @return - | ||
| 365 | * @globalvars none | ||
| 366 | * @exception none | ||
| 367 | * @pre none | ||
| 368 | * @post bit count of m_value trimmed to width | ||
| 369 | */ | ||
| 370 | inline void align() | ||
| 371 | { | ||
| 372 | m_value &= ((1 << m_width) - 1); | ||
| 373 | } | ||
| 374 | |||
| 375 | /* members */ | 354 | /* members */ |
| 376 | /** internal value of datatype */ | 355 | /** internal value of datatype */ |
| 377 | int m_value; | 356 | int m_value; |
diff --git a/ue4/mycpu/mycpu.cpp b/ue4/mycpu/mycpu.cpp index e9525d2..aefe0cb 100644 --- a/ue4/mycpu/mycpu.cpp +++ b/ue4/mycpu/mycpu.cpp | |||
| @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) | |||
| 180 | return 1; | 180 | return 1; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | if (bc < 2 || bc > 31) | 183 | if (bc < 2 || bc > 32) |
| 184 | { | 184 | { |
| 185 | cerr << me << ": Paramater 'format' must be inbetween 2 and 32." << endl; | 185 | cerr << me << ": Paramater 'format' must be inbetween 2 and 32." << endl; |
| 186 | return 1; | 186 | return 1; |
