diff --git a/src/libqof/qof/qofint128.cpp b/src/libqof/qof/qofint128.cpp index 8cc05806f4..02e9c2681b 100644 --- a/src/libqof/qof/qofint128.cpp +++ b/src/libqof/qof/qofint128.cpp @@ -64,6 +64,14 @@ QofInt128::QofInt128 (int64_t upper, int64_t lower, unsigned char flags) : m_flags {flags}, m_hi {upper}, m_lo {lower} {} +QofInt128& +QofInt128::zero () noexcept +{ + m_flags = 0; + m_lo = m_hi = UINT64_C(0); + return *this; +} + QofInt128::operator int64_t() const { if ((m_flags & neg) && isBig()) @@ -138,6 +146,16 @@ QofInt128::isZero() const noexcept return ((m_flags & (overflow | NaN)) == 0 && m_hi == 0 && m_lo == 0); } +QofInt128 +QofInt128::abs() const noexcept +{ + if (isNeg()) + return operator-(); + + return *this; +} + + QofInt128 QofInt128::operator-() const noexcept { diff --git a/src/libqof/qof/qofint128.hpp b/src/libqof/qof/qofint128.hpp index 6b365c51ff..3abff6480c 100644 --- a/src/libqof/qof/qofint128.hpp +++ b/src/libqof/qof/qofint128.hpp @@ -42,6 +42,7 @@ * on an overflowed or NaN QofInt128 will yield an overflowed or NaN * result, so calling routines need not check until the end of a * chained calculation. + * QofInt128 uses implicit copy and move constructors and implicit destructor. */ class QofInt128 { @@ -75,6 +76,15 @@ enum // Values for m_flags */ QofInt128 (int64_t upper, int64_t lower, unsigned char flags = '\0'); QofInt128 (uint64_t upper, uint64_t lower, unsigned char flags = '\0'); + +/** + * Clear the object. + * + * Sets all member variables to zero. + * @return A reference to the object for chaining. + */ + QofInt128& zero() noexcept; + /** * Compare function. * @@ -90,7 +100,7 @@ enum // Values for m_flags */ QofInt128 gcd (const QofInt128& b) const noexcept; /** - * Computes the Least Common Multiple between the object and paramter + * Computes the Least Common Multiple between the object and parameter * * @return A QofInt128 having the LCM. */ @@ -152,6 +162,7 @@ enum // Values for m_flags */ char* asCharBufR(char* buf) const noexcept; + QofInt128 abs() const noexcept; QofInt128 operator-() const noexcept; explicit operator bool() const noexcept;