Add increment, decrement, and shift-eauals operators to QofInt128.

They'll be needed for division.
This commit is contained in:
John Ralls 2014-11-17 12:09:55 -08:00
parent c7752d5d3c
commit 1c83db5896
2 changed files with 62 additions and 1 deletions

View File

@ -172,6 +172,30 @@ QofInt128::operator bool() const noexcept
return ! isZero ();
}
QofInt128&
QofInt128::operator++ () noexcept
{
return operator+=(UINT64_C(1));
}
QofInt128&
QofInt128::operator++ (int) noexcept
{
return operator+=(UINT64_C(1));
}
QofInt128&
QofInt128::operator-- () noexcept
{
return operator-=(UINT64_C(1));
}
QofInt128&
QofInt128::operator-- (int) noexcept
{
return operator-=(UINT64_C(1));
}
QofInt128&
QofInt128::operator+= (const QofInt128& b) noexcept
{
@ -187,6 +211,39 @@ QofInt128::operator+= (const QofInt128& b) noexcept
return *this;
}
QofInt128&
QofInt128::operator<<= (uint i) noexcept
{
if (i > maxbits)
{
m_flags &= 0xfe;
m_hi = 0;
m_lo = 0;
return *this;
}
uint64_t carry {(m_lo & (((1 << i) - 1) << (legbits - i)))};
m_lo <<= i;
m_hi <<= i;
m_hi += carry;
return *this;
}
QofInt128&
QofInt128::operator>>= (uint i) noexcept
{
if (i > maxbits)
{
m_flags &= 0xfe;
m_hi = 0;
m_lo = 0;
return *this;
}
uint64_t carry {(m_hi & ((1 << i) - 1))};
m_lo >>= i;
m_hi >>= i;
m_lo += (carry << (legbits - i));
return *this;
}
QofInt128&
QofInt128::operator-= (const QofInt128& b) noexcept

View File

@ -168,7 +168,11 @@ enum // Values for m_flags
explicit operator bool() const noexcept;
QofInt128& operator++ () noexcept;
QofInt128 operator++ (int) noexcept;
QofInt128& operator++ (int) noexcept;
QofInt128& operator-- () noexcept;
QofInt128& operator-- (int) noexcept;
QofInt128& operator<<= (uint i) noexcept;
QofInt128& operator>>= (uint i) noexcept;
QofInt128& operator+= (const QofInt128& b) noexcept;
QofInt128& operator-= (const QofInt128& b) noexcept;
QofInt128& operator*= (const QofInt128& b) noexcept;