Fix GncInt128 shift operators when shift amount will clear a leg.

This commit is contained in:
John Ralls 2017-01-30 12:59:45 -08:00
parent 4a134ae0b1
commit 570c8a8d60

View File

@ -309,11 +309,17 @@ GncInt128::operator<<= (unsigned int i) noexcept
m_lo = 0;
return *this;
}
if (i < legbits)
{
uint64_t carry {(m_lo & (((UINT64_C(1) << i) - 1) << (legbits - i)))};
m_lo <<= i;
m_hi <<= i;
m_hi += carry;
return *this;
}
m_hi = m_lo << (i - legbits);
m_lo = 0;
return *this;
}
GncInt128&
@ -326,11 +332,17 @@ GncInt128::operator>>= (unsigned int i) noexcept
m_lo = 0;
return *this;
}
if (i < legbits)
{
uint64_t carry {(m_hi & ((UINT64_C(1) << i) - 1))};
m_lo >>= i;
m_hi >>= i;
m_lo += (carry << (legbits - i));
return *this;
}
m_lo = m_hi >> (i - legbits);
m_hi = 0;
return *this;
}
GncInt128&