Changeset 970
- Timestamp:
- Sep 21, 2011, 7:10:31 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/real.cpp
r969 r970 46 46 47 47 return u.f; 48 } 49 50 real real::operator -() 51 { 52 m_signexp ^= 0x80000000u; 53 return *this; 54 } 55 56 real real::operator +(real const &x) const 57 { 58 if ((m_signexp << 1) < (x.m_signexp << 1)) 59 return x + *this; 60 61 /* For now, assume both numbers are positive. */ 62 real ret; 63 64 int e1 = (m_signexp & 0x7fffffffu) - (1 << 30) + 1; 65 int e2 = (x.m_signexp & 0x7fffffffu) - (1 << 30) + 1; 66 67 int bigoff = (e1 - e2) / (sizeof(uint16_t) * 8); 68 int off = e1 - e2 - bigoff * (sizeof(uint16_t) * 8); 69 70 ret.m_signexp = m_signexp; 71 72 uint32_t carry = 0; 73 for (int i = 0; i < BIGITS; i++) 74 { 75 carry = m_mantissa[BIGITS - 1 - i]; 76 if (BIGITS - 1 - i - bigoff >= 0) 77 carry += x.m_mantissa[BIGITS - 1 - i - bigoff] >> off; 78 else if (BIGITS - 1 - i - bigoff == -1) 79 carry += 0x0001u >> off; 80 81 if (BIGITS - 1 - i - bigoff - 1 >= 0) 82 carry += (x.m_mantissa[BIGITS - 1 - i - bigoff - 1] << (16 - off)) & 0xffffu; 83 else if (BIGITS - 1 - i - bigoff - 1 == -1) 84 carry += 0x0001u << (16 - off); 85 86 ret.m_mantissa[BIGITS - 1 - i] = carry; 87 carry >>= 16; 88 } 89 90 /* Renormalise in case we overflowed the mantissa */ 91 if (carry) 92 { 93 carry--; 94 for (int i = 0; i < BIGITS; i++) 95 { 96 uint16_t tmp = ret.m_mantissa[i]; 97 ret.m_mantissa[i] = (carry << 15) | (tmp >> 1); 98 carry = tmp & 0x0001u; 99 } 100 ret.m_signexp++; 101 } 102 103 return ret; 48 104 } 49 105 -
trunk/src/real.h
r969 r970 31 31 32 32 operator float() const; 33 real operator -(); 34 real operator +(real const &x) const; 33 35 real operator *(real const &x) const; 34 36 -
trunk/test/unit/real.cpp
r969 r970 35 35 } 36 36 37 LOLUNIT_TEST(test_real_add) 38 { 39 LOLUNIT_ASSERT(true); 40 } 41 37 42 LOLUNIT_TEST(test_real_mul) 38 43 {
Note: See TracChangeset
for help on using the changeset viewer.