diff --git a/src/libqof/qof/qofint128.cpp b/src/libqof/qof/qofint128.cpp index 02e9c2681b..c322b01d2d 100644 --- a/src/libqof/qof/qofint128.cpp +++ b/src/libqof/qof/qofint128.cpp @@ -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 diff --git a/src/libqof/qof/qofint128.hpp b/src/libqof/qof/qofint128.hpp index 3abff6480c..235bfbbc88 100644 --- a/src/libqof/qof/qofint128.hpp +++ b/src/libqof/qof/qofint128.hpp @@ -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;