Changeset 1029
Legend:
 Unmodified
 Added
 Removed

trunk/src/real.cpp
r1026 r1029 23 23 { 24 24 25 real::real(float f) { *this = (double)f; } 26 real::real(int i) { *this = (double)i; } 27 real::real(unsigned int i) { *this = (double)i; } 25 real::real() 26 { 27 m_mantissa = new uint32_t[BIGITS]; 28 m_signexp = 0; 29 } 30 31 real::real(real const &x) 32 { 33 m_mantissa = new uint32_t[BIGITS]; 34 memcpy(m_mantissa, x.m_mantissa, BIGITS * sizeof(uint32_t)); 35 m_signexp = x.m_signexp; 36 } 37 38 real const &real::operator =(real const &x) 39 { 40 if (&x != this) 41 { 42 memcpy(m_mantissa, x.m_mantissa, BIGITS * sizeof(uint32_t)); 43 m_signexp = x.m_signexp; 44 } 45 46 return *this; 47 } 48 49 real::~real() 50 { 51 delete[] m_mantissa; 52 } 53 54 real::real(float f) { new(this) real((double)f); } 55 real::real(int i) { new(this) real((double)i); } 56 real::real(unsigned int i) { new(this) real((double)i); } 28 57 29 58 real::real(double d) 30 59 { 60 new(this) real(); 61 31 62 union { double d; uint64_t x; } u = { d }; 32 63 … … 199 230 for (int i = 0; i < bigoff; i++) 200 231 { 201 carry = x.m_mantissa[BIGITS  i];232 carry = x.m_mantissa[BIGITS  1  i]; 202 233 /* Emulates a signed shift */ 203 234 carry >>= BIGIT_BITS; 204 235 carry = carry << BIGIT_BITS; 205 236 } 206 carry = x.m_mantissa[BIGITS  1  bigoff] & (((int64_t)1 << off)  1); 237 if (bigoff < BIGITS) 238 carry = x.m_mantissa[BIGITS  1  bigoff] & (((int64_t)1 << off)  1); 207 239 carry /= (int64_t)1 << off; 208 240 … … 345 377 } 346 378 347 real &real::operator +=(real const &x)379 real const &real::operator +=(real const &x) 348 380 { 349 381 real tmp = *this; … … 351 383 } 352 384 353 real &real::operator =(real const &x)385 real const &real::operator =(real const &x) 354 386 { 355 387 real tmp = *this; … … 357 389 } 358 390 359 real &real::operator *=(real const &x)391 real const &real::operator *=(real const &x) 360 392 { 361 393 real tmp = *this; … … 363 395 } 364 396 365 real &real::operator /=(real const &x)397 real const &real::operator /=(real const &x) 366 398 { 367 399 real tmp = *this; … … 381 413 } 382 414 383 real &real::operator <<=(int x)415 real const &real::operator <<=(int x) 384 416 { 385 417 if (m_signexp << 1) … … 388 420 } 389 421 390 real &real::operator >>=(int x)422 real const &real::operator >>=(int x) 391 423 { 392 424 if (m_signexp << 1) … … 403 435 return false; 404 436 405 return memcmp(m_mantissa, x.m_mantissa, sizeof(m_mantissa)) == 0;437 return memcmp(m_mantissa, x.m_mantissa, BIGITS * sizeof(uint32_t)) == 0; 406 438 } 407 439 
trunk/src/real.h
r1026 r1029 25 25 { 26 26 public: 27 inline real() { } 27 real(); 28 real(real const &x); 29 real const &operator =(real const &x); 30 ~real(); 28 31 29 32 real(float f); … … 43 46 real operator *(real const &x) const; 44 47 real operator /(real const &x) const; 45 real &operator +=(real const &x);46 real &operator =(real const &x);47 real &operator *=(real const &x);48 real &operator /=(real const &x);48 real const &operator +=(real const &x); 49 real const &operator =(real const &x); 50 real const &operator *=(real const &x); 51 real const &operator /=(real const &x); 49 52 50 53 real operator <<(int x) const; 51 54 real operator >>(int x) const; 52 real &operator <<=(int x);53 real &operator >>=(int x);55 real const &operator <<=(int x); 56 real const &operator >>=(int x); 54 57 55 58 bool operator ==(real const &x) const; … … 134 137 135 138 private: 136 uint32_t m_size;139 uint32_t *m_mantissa; 137 140 uint32_t m_signexp; 138 uint32_t m_mantissa[BIGITS];139 141 }; 140 142
Note: See TracChangeset
for help on using the changeset viewer.