mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add zero and abs functions to QofInt128.
This commit is contained in:
parent
1e6855efe5
commit
c7752d5d3c
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user