Rename QofInt128 to GncInt128.

It has nothing to do with QOF.
This commit is contained in:
John Ralls 2014-12-05 15:46:07 -08:00
parent d35bcdb877
commit 8a3e368791
9 changed files with 304 additions and 305 deletions

View File

@ -429,6 +429,7 @@ src/import-export/qif-imp/gncmod-qif-import.c
src/import-export/qif-imp/gnc-plugin-qif-import.c src/import-export/qif-imp/gnc-plugin-qif-import.c
[type: gettext/gsettings]src/import-export/qif-imp/gschemas/org.gnucash.dialogs.import.qif.gschema.xml.in.in [type: gettext/gsettings]src/import-export/qif-imp/gschemas/org.gnucash.dialogs.import.qif.gschema.xml.in.in
src/libqof/qof/gnc-date.cpp src/libqof/qof/gnc-date.cpp
src/libqof/qof/gnc-int128.cpp
src/libqof/qof/gnc-numeric.cpp src/libqof/qof/gnc-numeric.cpp
src/libqof/qof/gnc-rational.cpp src/libqof/qof/gnc-rational.cpp
src/libqof/qof/guid.cpp src/libqof/qof/guid.cpp
@ -442,7 +443,6 @@ src/libqof/qof/qofevent.cpp
src/libqof/qof/qofid.cpp src/libqof/qof/qofid.cpp
src/libqof/qof/qofinstance.cpp src/libqof/qof/qofinstance.cpp
src/libqof/qof/qoflog.cpp src/libqof/qof/qoflog.cpp
src/libqof/qof/qofint128.cpp
src/libqof/qof/qofobject.cpp src/libqof/qof/qofobject.cpp
src/libqof/qof/qofquerycore.cpp src/libqof/qof/qofquerycore.cpp
src/libqof/qof/qofquery.cpp src/libqof/qof/qofquery.cpp

View File

@ -24,6 +24,7 @@ AM_CPPFLAGS = \
libgnc_qof_la_SOURCES = \ libgnc_qof_la_SOURCES = \
gnc-date.cpp \ gnc-date.cpp \
gnc-int128.cpp \
gnc-numeric.cpp \ gnc-numeric.cpp \
gnc-rational.cpp \ gnc-rational.cpp \
guid.cpp \ guid.cpp \
@ -37,7 +38,6 @@ libgnc_qof_la_SOURCES = \
qofevent.cpp \ qofevent.cpp \
qofid.cpp \ qofid.cpp \
qofinstance.cpp \ qofinstance.cpp \
qofint128.cpp \
qoflog.cpp \ qoflog.cpp \
qofobject.cpp \ qofobject.cpp \
qofquery.cpp \ qofquery.cpp \
@ -82,7 +82,7 @@ noinst_HEADERS = \
qofbook-p.h \ qofbook-p.h \
qofclass-p.h \ qofclass-p.h \
qofevent-p.h \ qofevent-p.h \
qofint128.hpp \ gnc-int128.hpp \
qofobject-p.h \ qofobject-p.h \
qofquery-p.h \ qofquery-p.h \
qofquerycore-p.h \ qofquerycore-p.h \

View File

@ -27,7 +27,7 @@ extern "C"
#include <inttypes.h> #include <inttypes.h>
} }
#include "qofint128.hpp" #include "gnc-int128.hpp"
#include <iomanip> #include <iomanip>
#include <utility> #include <utility>
@ -39,22 +39,22 @@ extern "C"
*/ */
namespace { namespace {
static const uint sublegs = QofInt128::numlegs * 2; static const uint sublegs = GncInt128::numlegs * 2;
static const uint sublegbits = QofInt128::legbits / 2; static const uint sublegbits = GncInt128::legbits / 2;
static const uint64_t sublegmask = (UINT64_C(1) << sublegbits) - 1; static const uint64_t sublegmask = (UINT64_C(1) << sublegbits) - 1;
} }
QofInt128::QofInt128 () : m_flags {}, m_hi {0}, m_lo {0}{} GncInt128::GncInt128 () : m_flags {}, m_hi {0}, m_lo {0}{}
QofInt128::QofInt128 (int64_t lower) : GncInt128::GncInt128 (int64_t lower) :
m_flags {static_cast<unsigned char>(lower < 0 ? neg : pos)}, m_flags {static_cast<unsigned char>(lower < 0 ? neg : pos)},
m_hi {0}, m_hi {0},
m_lo {static_cast<uint64_t>(lower < 0 ? -lower : lower)} {} m_lo {static_cast<uint64_t>(lower < 0 ? -lower : lower)} {}
QofInt128::QofInt128 (uint64_t lower) : GncInt128::GncInt128 (uint64_t lower) :
m_flags {}, m_hi {0}, m_lo {lower} {} m_flags {}, m_hi {0}, m_lo {lower} {}
QofInt128::QofInt128 (int64_t upper, int64_t lower, unsigned char flags) : GncInt128::GncInt128 (int64_t upper, int64_t lower, unsigned char flags) :
m_flags {static_cast<unsigned char>(flags ^ (upper < 0 ? neg : m_flags {static_cast<unsigned char>(flags ^ (upper < 0 ? neg :
upper == 0 && lower < 0 ? neg : pos))}, upper == 0 && lower < 0 ? neg : pos))},
m_hi {static_cast<uint64_t>(upper < 0 ? -upper : upper)}, m_hi {static_cast<uint64_t>(upper < 0 ? -upper : upper)},
@ -68,19 +68,19 @@ QofInt128::QofInt128 (int64_t upper, int64_t lower, unsigned char flags) :
m_hi >>= 1; m_hi >>= 1;
} }
QofInt128::QofInt128 (uint64_t upper, uint64_t lower, unsigned char flags) : GncInt128::GncInt128 (uint64_t upper, uint64_t lower, unsigned char flags) :
m_flags {flags}, m_hi {upper}, m_flags {flags}, m_hi {upper},
m_lo {lower} {} m_lo {lower} {}
QofInt128& GncInt128&
QofInt128::zero () noexcept GncInt128::zero () noexcept
{ {
m_flags = 0; m_flags = 0;
m_lo = m_hi = UINT64_C(0); m_lo = m_hi = UINT64_C(0);
return *this; return *this;
} }
QofInt128::operator int64_t() const GncInt128::operator int64_t() const
{ {
if ((m_flags & neg) && isBig()) if ((m_flags & neg) && isBig())
throw std::underflow_error ("Negative value to large to represent as int64_t"); throw std::underflow_error ("Negative value to large to represent as int64_t");
@ -90,7 +90,7 @@ QofInt128::operator int64_t() const
return m_flags & neg ? -retval : retval; return m_flags & neg ? -retval : retval;
} }
QofInt128::operator uint64_t() const GncInt128::operator uint64_t() const
{ {
if (m_flags & neg) if (m_flags & neg)
throw std::underflow_error ("Can't represent negative value as uint64_t"); throw std::underflow_error ("Can't represent negative value as uint64_t");
@ -101,7 +101,7 @@ QofInt128::operator uint64_t() const
int int
QofInt128::cmp (const QofInt128& b) const noexcept GncInt128::cmp (const GncInt128& b) const noexcept
{ {
if (m_flags & (overflow | NaN)) if (m_flags & (overflow | NaN))
return -1; return -1;
@ -127,8 +127,8 @@ QofInt128::cmp (const QofInt128& b) const noexcept
/* Knuth 4.5.3 Algo B, recommended by GMP as much faster than Algo A (Euclidean /* Knuth 4.5.3 Algo B, recommended by GMP as much faster than Algo A (Euclidean
* method). * method).
*/ */
QofInt128 GncInt128
QofInt128::gcd(QofInt128 b) const noexcept GncInt128::gcd(GncInt128 b) const noexcept
{ {
if (b.isZero()) if (b.isZero())
return *this; return *this;
@ -140,7 +140,7 @@ QofInt128::gcd(QofInt128 b) const noexcept
if (isOverflow() || isNan()) if (isOverflow() || isNan())
return *this; return *this;
QofInt128 a (isNeg() ? -(*this) : *this); GncInt128 a (isNeg() ? -(*this) : *this);
if (b.isNeg()) b = -b; if (b.isNeg()) b = -b;
uint k {}; uint k {};
@ -151,7 +151,7 @@ QofInt128::gcd(QofInt128 b) const noexcept
b >>= 1; b >>= 1;
++k; ++k;
} }
QofInt128 t {a & one ? -b : a}; //B2 GncInt128 t {a & one ? -b : a}; //B2
while (a != b) while (a != b)
{ {
while (t && (t & one ^ one)) t >>= 1; //B3 & B4 while (t && (t & one ^ one)) t >>= 1; //B3 & B4
@ -166,22 +166,22 @@ QofInt128::gcd(QofInt128 b) const noexcept
/* Since u * v = gcd(u, v) * lcm(u, v), we find lcm by u / gcd * v. */ /* Since u * v = gcd(u, v) * lcm(u, v), we find lcm by u / gcd * v. */
QofInt128 GncInt128
QofInt128::lcm(const QofInt128& b) const noexcept GncInt128::lcm(const GncInt128& b) const noexcept
{ {
auto common = gcd(b); auto common = gcd(b);
return *this / common * b.abs(); //Preserve our sign, discard the other's. return *this / common * b.abs(); //Preserve our sign, discard the other's.
} }
/* Knuth section 4.6.3 */ /* Knuth section 4.6.3 */
QofInt128 GncInt128
QofInt128::pow(uint b) const noexcept GncInt128::pow(uint b) const noexcept
{ {
if (isZero() || (m_lo == 1 && m_hi == 0) || isNan() || isOverflow()) if (isZero() || (m_lo == 1 && m_hi == 0) || isNan() || isOverflow())
return *this; return *this;
if (b == 0) if (b == 0)
return QofInt128 (1); return GncInt128 (1);
QofInt128 retval (1), squares = *this; GncInt128 retval (1), squares = *this;
while (b && !retval.isOverflow()) while (b && !retval.isOverflow())
{ {
if (b & 1) if (b & 1)
@ -193,37 +193,37 @@ QofInt128::pow(uint b) const noexcept
} }
bool bool
QofInt128::isNeg () const noexcept GncInt128::isNeg () const noexcept
{ {
return (m_flags & neg); return (m_flags & neg);
} }
bool bool
QofInt128::isBig () const noexcept GncInt128::isBig () const noexcept
{ {
return (m_hi || m_lo > INT64_MAX); return (m_hi || m_lo > INT64_MAX);
} }
bool bool
QofInt128::isOverflow () const noexcept GncInt128::isOverflow () const noexcept
{ {
return (m_flags & overflow); return (m_flags & overflow);
} }
bool bool
QofInt128::isNan () const noexcept GncInt128::isNan () const noexcept
{ {
return (m_flags & NaN); return (m_flags & NaN);
} }
bool bool
QofInt128::isZero() const noexcept GncInt128::isZero() const noexcept
{ {
return ((m_flags & (overflow | NaN)) == 0 && m_hi == 0 && m_lo == 0); return ((m_flags & (overflow | NaN)) == 0 && m_hi == 0 && m_lo == 0);
} }
QofInt128 GncInt128
QofInt128::abs() const noexcept GncInt128::abs() const noexcept
{ {
if (isNeg()) if (isNeg())
return operator-(); return operator-();
@ -232,7 +232,7 @@ QofInt128::abs() const noexcept
} }
uint uint
QofInt128::bits() const noexcept GncInt128::bits() const noexcept
{ {
uint bits {static_cast<uint>(m_hi == 0 ? 0 : 64)}; uint bits {static_cast<uint>(m_hi == 0 ? 0 : 64)};
uint64_t temp {(m_hi == 0 ? m_lo : m_hi)}; uint64_t temp {(m_hi == 0 ? m_lo : m_hi)};
@ -242,8 +242,8 @@ QofInt128::bits() const noexcept
} }
QofInt128 GncInt128
QofInt128::operator-() const noexcept GncInt128::operator-() const noexcept
{ {
auto retval = *this; auto retval = *this;
if (isNeg()) if (isNeg())
@ -253,37 +253,37 @@ QofInt128::operator-() const noexcept
return retval; return retval;
} }
QofInt128::operator bool() const noexcept GncInt128::operator bool() const noexcept
{ {
return ! isZero (); return ! isZero ();
} }
QofInt128& GncInt128&
QofInt128::operator++ () noexcept GncInt128::operator++ () noexcept
{ {
return operator+=(UINT64_C(1)); return operator+=(UINT64_C(1));
} }
QofInt128& GncInt128&
QofInt128::operator++ (int) noexcept GncInt128::operator++ (int) noexcept
{ {
return operator+=(UINT64_C(1)); return operator+=(UINT64_C(1));
} }
QofInt128& GncInt128&
QofInt128::operator-- () noexcept GncInt128::operator-- () noexcept
{ {
return operator-=(UINT64_C(1)); return operator-=(UINT64_C(1));
} }
QofInt128& GncInt128&
QofInt128::operator-- (int) noexcept GncInt128::operator-- (int) noexcept
{ {
return operator-=(UINT64_C(1)); return operator-=(UINT64_C(1));
} }
QofInt128& GncInt128&
QofInt128::operator+= (const QofInt128& b) noexcept GncInt128::operator+= (const GncInt128& b) noexcept
{ {
if (b.isOverflow()) if (b.isOverflow())
m_flags |= overflow; m_flags |= overflow;
@ -304,8 +304,8 @@ QofInt128::operator+= (const QofInt128& b) noexcept
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator<<= (uint i) noexcept GncInt128::operator<<= (uint i) noexcept
{ {
if (i > maxbits) if (i > maxbits)
{ {
@ -321,8 +321,8 @@ QofInt128::operator<<= (uint i) noexcept
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator>>= (uint i) noexcept GncInt128::operator>>= (uint i) noexcept
{ {
if (i > maxbits) if (i > maxbits)
{ {
@ -338,8 +338,8 @@ QofInt128::operator>>= (uint i) noexcept
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator-= (const QofInt128& b) noexcept GncInt128::operator-= (const GncInt128& b) noexcept
{ {
if (b.isOverflow()) if (b.isOverflow())
m_flags |= overflow; m_flags |= overflow;
@ -383,8 +383,8 @@ QofInt128::operator-= (const QofInt128& b) noexcept
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator*= (const QofInt128& b) noexcept GncInt128::operator*= (const GncInt128& b) noexcept
{ {
/* Test for 0 first */ /* Test for 0 first */
if (isZero() || b.isZero()) if (isZero() || b.isZero())
@ -423,7 +423,7 @@ QofInt128::operator*= (const QofInt128& b) noexcept
} }
/* This is Knuth's "classical" multi-precision multiplication algorithm /* This is Knuth's "classical" multi-precision multiplication algorithm
* truncated to a QofInt128 result with the loop unrolled for clarity and with * truncated to a GncInt128 result with the loop unrolled for clarity and with
* overflow and zero checks beforehand to save time. See Donald Knuth, "The Art * overflow and zero checks beforehand to save time. See Donald Knuth, "The Art
* of Computer Programming Volume 2: Seminumerical Algorithms", Addison-Wesley, * of Computer Programming Volume 2: Seminumerical Algorithms", Addison-Wesley,
* 1998, p 268. * 1998, p 268.
@ -488,7 +488,7 @@ namespace {
*/ */
/* We're using arrays here instead of vectors to avoid an alloc. */ /* We're using arrays here instead of vectors to avoid an alloc. */
void void
div_multi_leg (uint64_t* u, size_t m, uint64_t* v, size_t n, QofInt128& q, QofInt128& r) noexcept div_multi_leg (uint64_t* u, size_t m, uint64_t* v, size_t n, GncInt128& q, GncInt128& r) noexcept
{ {
/* D1, Normalization */ /* D1, Normalization */
uint64_t qv[sublegs] {}; uint64_t qv[sublegs] {};
@ -578,14 +578,14 @@ div_multi_leg (uint64_t* u, size_t m, uint64_t* v, size_t n, QofInt128& q, QofIn
u[j + n] += carry; u[j + n] += carry;
} }
}//D7 }//D7
q = QofInt128 ((qv[3] << sublegbits) + qv[2], (qv[1] << sublegbits) + qv[0]); q = GncInt128 ((qv[3] << sublegbits) + qv[2], (qv[1] << sublegbits) + qv[0]);
r = QofInt128 ((u[3] << sublegbits) + u[2], (u[1] << sublegbits) + u[0]); r = GncInt128 ((u[3] << sublegbits) + u[2], (u[1] << sublegbits) + u[0]);
r /= d; r /= d;
if (negative) q = -q; if (negative) q = -q;
} }
void void
div_single_leg (uint64_t* u, size_t m, uint64_t v, QofInt128& q, QofInt128& r) noexcept div_single_leg (uint64_t* u, size_t m, uint64_t v, GncInt128& q, GncInt128& r) noexcept
{ {
uint64_t qv[sublegs] {}; uint64_t qv[sublegs] {};
uint64_t carry {}; uint64_t carry {};
@ -602,15 +602,15 @@ div_single_leg (uint64_t* u, size_t m, uint64_t v, QofInt128& q, QofInt128& r) n
u[i] %= v; u[i] %= v;
} }
q = QofInt128 ((qv[3] << sublegbits) + qv[2], (qv[1] << sublegbits) + qv[0]); q = GncInt128 ((qv[3] << sublegbits) + qv[2], (qv[1] << sublegbits) + qv[0]);
r = QofInt128 ((u[3] << sublegbits) + u[2], (u[1] << sublegbits) + u[0]); r = GncInt128 ((u[3] << sublegbits) + u[2], (u[1] << sublegbits) + u[0]);
if (negative) q = -q; if (negative) q = -q;
} }
}// namespace }// namespace
void void
QofInt128::div (const QofInt128& b, QofInt128& q, QofInt128& r) noexcept GncInt128::div (const GncInt128& b, GncInt128& q, GncInt128& r) noexcept
{ {
if (isOverflow() || b.isOverflow()) if (isOverflow() || b.isOverflow())
{ {
@ -670,19 +670,19 @@ QofInt128::div (const QofInt128& b, QofInt128& q, QofInt128& r) noexcept
return div_multi_leg (u, m, v, n, q, r); return div_multi_leg (u, m, v, n, q, r);
} }
QofInt128& GncInt128&
QofInt128::operator/= (const QofInt128& b) noexcept GncInt128::operator/= (const GncInt128& b) noexcept
{ {
QofInt128 q {}, r {}; GncInt128 q {}, r {};
div(b, q, r); div(b, q, r);
std::swap (*this, q); std::swap (*this, q);
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator%= (const QofInt128& b) noexcept GncInt128::operator%= (const GncInt128& b) noexcept
{ {
QofInt128 q {}, r {}; GncInt128 q {}, r {};
div(b, q, r); div(b, q, r);
std::swap (*this, r); std::swap (*this, r);
if (q.isNan()) if (q.isNan())
@ -690,8 +690,8 @@ QofInt128::operator%= (const QofInt128& b) noexcept
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator&= (const QofInt128& b) noexcept GncInt128::operator&= (const GncInt128& b) noexcept
{ {
if (b.isOverflow()) if (b.isOverflow())
m_flags |= overflow; m_flags |= overflow;
@ -706,16 +706,16 @@ QofInt128::operator&= (const QofInt128& b) noexcept
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator|= (const QofInt128& b) noexcept GncInt128::operator|= (const GncInt128& b) noexcept
{ {
m_hi ^= b.m_hi; m_hi ^= b.m_hi;
m_lo ^= b.m_lo; m_lo ^= b.m_lo;
return *this; return *this;
} }
QofInt128& GncInt128&
QofInt128::operator^= (const QofInt128& b) noexcept GncInt128::operator^= (const GncInt128& b) noexcept
{ {
if (b.isOverflow()) if (b.isOverflow())
m_flags |= overflow; m_flags |= overflow;
@ -775,7 +775,7 @@ decimal_from_binary (uint64_t d[dec_array_size], uint64_t hi, uint64_t lo)
static const uint8_t char_buf_size {41}; //39 digits plus sign and trailing null static const uint8_t char_buf_size {41}; //39 digits plus sign and trailing null
char* char*
QofInt128::asCharBufR(char* buf) const noexcept GncInt128::asCharBufR(char* buf) const noexcept
{ {
if (isOverflow()) if (isOverflow())
{ {
@ -809,7 +809,7 @@ QofInt128::asCharBufR(char* buf) const noexcept
} }
std::ostream& std::ostream&
operator<< (std::ostream& stream, const QofInt128& a) noexcept operator<< (std::ostream& stream, const GncInt128& a) noexcept
{ {
char buf[char_buf_size] {}; char buf[char_buf_size] {};
stream << a.asCharBufR (buf); stream << a.asCharBufR (buf);
@ -817,105 +817,105 @@ operator<< (std::ostream& stream, const QofInt128& a) noexcept
} }
bool bool
operator== (const QofInt128& a, const QofInt128& b) noexcept operator== (const GncInt128& a, const GncInt128& b) noexcept
{ {
return a.cmp(b) == 0; return a.cmp(b) == 0;
} }
bool bool
operator!= (const QofInt128& a, const QofInt128& b) noexcept operator!= (const GncInt128& a, const GncInt128& b) noexcept
{ {
return a.cmp(b) != 0; return a.cmp(b) != 0;
} }
bool bool
operator< (const QofInt128& a, const QofInt128& b) noexcept operator< (const GncInt128& a, const GncInt128& b) noexcept
{ {
return a.cmp(b) < 0; return a.cmp(b) < 0;
} }
bool bool
operator> (const QofInt128& a, const QofInt128& b) noexcept operator> (const GncInt128& a, const GncInt128& b) noexcept
{ {
return a.cmp(b) > 0; return a.cmp(b) > 0;
} }
bool bool
operator<= (const QofInt128& a, const QofInt128& b) noexcept operator<= (const GncInt128& a, const GncInt128& b) noexcept
{ {
return a.cmp(b) <= 0; return a.cmp(b) <= 0;
} }
bool bool
operator>= (const QofInt128& a, const QofInt128& b) noexcept operator>= (const GncInt128& a, const GncInt128& b) noexcept
{ {
return a.cmp(b) >= 0; return a.cmp(b) >= 0;
} }
QofInt128 GncInt128
operator+ (QofInt128 a, const QofInt128& b) noexcept operator+ (GncInt128 a, const GncInt128& b) noexcept
{ {
a += b; a += b;
return a; return a;
} }
QofInt128 GncInt128
operator- (QofInt128 a, const QofInt128& b) noexcept operator- (GncInt128 a, const GncInt128& b) noexcept
{ {
a -= b; a -= b;
return a; return a;
} }
QofInt128 GncInt128
operator* (QofInt128 a, const QofInt128& b) noexcept operator* (GncInt128 a, const GncInt128& b) noexcept
{ {
a *= b; a *= b;
return a; return a;
} }
QofInt128 GncInt128
operator/ (QofInt128 a, const QofInt128& b) noexcept operator/ (GncInt128 a, const GncInt128& b) noexcept
{ {
a /= b; a /= b;
return a; return a;
} }
QofInt128 GncInt128
operator% (QofInt128 a, const QofInt128& b) noexcept operator% (GncInt128 a, const GncInt128& b) noexcept
{ {
a %= b; a %= b;
return a; return a;
} }
QofInt128 GncInt128
operator& (QofInt128 a, const QofInt128& b) noexcept operator& (GncInt128 a, const GncInt128& b) noexcept
{ {
a &= b; a &= b;
return a; return a;
} }
QofInt128 GncInt128
operator| (QofInt128 a, const QofInt128& b) noexcept operator| (GncInt128 a, const GncInt128& b) noexcept
{ {
a |= b; a |= b;
return a; return a;
} }
QofInt128 GncInt128
operator^ (QofInt128 a, const QofInt128& b) noexcept operator^ (GncInt128 a, const GncInt128& b) noexcept
{ {
a ^= b; a ^= b;
return a; return a;
} }
QofInt128 GncInt128
operator<< (QofInt128 a, uint b) noexcept operator<< (GncInt128 a, uint b) noexcept
{ {
a <<= b; a <<= b;
return a; return a;
} }
QofInt128 GncInt128
operator>> (QofInt128 a, uint b) noexcept operator>> (GncInt128 a, uint b) noexcept
{ {
a >>= b; a >>= b;
return a; return a;

View File

@ -22,8 +22,8 @@
* * * *
*******************************************************************/ *******************************************************************/
#ifndef QOFINT128_H #ifndef GNCINT128_H
#define QOFINT128_H #define GNCINT128_H
#include <stdint.h> #include <stdint.h>
@ -39,12 +39,12 @@
* All the usual operators are provided. Only the explicit integer * All the usual operators are provided. Only the explicit integer
* conversions throw; all other errors are indicated by the overflow * conversions throw; all other errors are indicated by the overflow
* and NaN ("Not a Number") flags. Note that performing any operation * and NaN ("Not a Number") flags. Note that performing any operation
* on an overflowed or NaN QofInt128 will yield an overflowed or NaN * on an overflowed or NaN Gncint128 will yield an overflowed or NaN
* result, so calling routines need not check until the end of a * result, so calling routines need not check until the end of a
* chained calculation. * chained calculation.
* QofInt128 uses implicit copy and move constructors and implicit destructor. * GncInt128 uses implicit copy and move constructors and implicit destructor.
*/ */
class QofInt128 class GncInt128
{ {
unsigned char m_flags; unsigned char m_flags;
uint64_t m_hi; uint64_t m_hi;
@ -63,35 +63,35 @@ enum // Values for m_flags
NaN = 4 NaN = 4
}; };
QofInt128 (); GncInt128 ();
QofInt128 (int16_t lower) : QofInt128{static_cast<int64_t>(lower)} {}; GncInt128 (int16_t lower) : GncInt128{static_cast<int64_t>(lower)} {};
QofInt128 (uint16_t lower) : QofInt128{static_cast<uint64_t>(lower)} {}; GncInt128 (uint16_t lower) : GncInt128{static_cast<uint64_t>(lower)} {};
QofInt128 (int32_t lower) : QofInt128{static_cast<int64_t>(lower)} {}; GncInt128 (int32_t lower) : GncInt128{static_cast<int64_t>(lower)} {};
QofInt128 (uint32_t lower) : QofInt128{static_cast<uint64_t>(lower)} {}; GncInt128 (uint32_t lower) : GncInt128{static_cast<uint64_t>(lower)} {};
QofInt128 (int64_t lower); GncInt128 (int64_t lower);
QofInt128 (uint64_t lower); GncInt128 (uint64_t lower);
/** /**
* Construct a QofInt128 from two int64_t. * Construct a GncInt128 from two int64_t.
* *
* N.B.: If the two parameters are of differing sign, it's taken to * N.B.: If the two parameters are of differing sign, it's taken to
* mean that the lower magnitude is *reducing* the magnitude of the * mean that the lower magnitude is *reducing* the magnitude of the
* upper, so the lower magnitude will be subracted from UINT64_MAX to * upper, so the lower magnitude will be subracted from UINT64_MAX to
* obtain the lower limb value. * obtain the lower limb value.
*/ */
QofInt128 (int16_t upper, int16_t lower, unsigned char flags = '\0') : GncInt128 (int16_t upper, int16_t lower, unsigned char flags = '\0') :
QofInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower), GncInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower),
flags} {}; flags} {};
QofInt128 (uint16_t upper, uint16_t lower, unsigned char flags = '\0') : GncInt128 (uint16_t upper, uint16_t lower, unsigned char flags = '\0') :
QofInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower), GncInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower),
flags} {}; flags} {};
QofInt128 (int32_t upper, int32_t lower, unsigned char flags = '\0') : GncInt128 (int32_t upper, int32_t lower, unsigned char flags = '\0') :
QofInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower), GncInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower),
flags} {}; flags} {};
QofInt128 (uint32_t upper, uint32_t lower, unsigned char flags = '\0') : GncInt128 (uint32_t upper, uint32_t lower, unsigned char flags = '\0') :
QofInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower), GncInt128{static_cast<int64_t>(upper), static_cast<int64_t>(lower),
flags} {}; flags} {};
QofInt128 (int64_t upper, int64_t lower, unsigned char flags = '\0'); GncInt128 (int64_t upper, int64_t lower, unsigned char flags = '\0');
QofInt128 (uint64_t upper, uint64_t lower, unsigned char flags = '\0'); GncInt128 (uint64_t upper, uint64_t lower, unsigned char flags = '\0');
/** /**
* Clear the object. * Clear the object.
@ -99,7 +99,7 @@ enum // Values for m_flags
* Sets all member variables to zero. * Sets all member variables to zero.
* @return A reference to the object for chaining. * @return A reference to the object for chaining.
*/ */
QofInt128& zero() noexcept; GncInt128& zero() noexcept;
/** /**
* Compare function. * Compare function.
@ -107,29 +107,29 @@ enum // Values for m_flags
* @return -1 if the object is less than the parameter, 0 if they're * @return -1 if the object is less than the parameter, 0 if they're
* equal, and 1 if the object is greater. * equal, and 1 if the object is greater.
*/ */
int cmp (const QofInt128& b) const noexcept; int cmp (const GncInt128& b) const noexcept;
/** /**
* Computes the Greatest Common Divisor between the object and paramter * Computes the Greatest Common Divisor between the object and paramter
* *
* @return A QofInt128 having the GCD. * @return A GncInt128 having the GCD.
*/ */
QofInt128 gcd (QofInt128 b) const noexcept; GncInt128 gcd (GncInt128 b) const noexcept;
/** /**
* Computes the Least Common Multiple between the object and parameter * Computes the Least Common Multiple between the object and parameter
* *
* @return A QofInt128 having the LCM. * @return A GncInt128 having the LCM.
*/ */
QofInt128 lcm (const QofInt128& b) const noexcept; GncInt128 lcm (const GncInt128& b) const noexcept;
/** /**
* Computes the object raised to the parameter's power * Computes the object raised to the parameter's power
* *
* @param b The power to raise this to. No point in taking a QofInt128, any * @param b The power to raise this to. No point in taking a GncInt128, any
* value greater than 128 would overflow on any value other than 1. * value greater than 128 would overflow on any value other than 1.
* @return A QofInt128 * @return A GncInt128
*/ */
QofInt128 pow (uint n) const noexcept; GncInt128 pow (uint n) const noexcept;
/** /**
* Computes a quotient and a remainder, passed as reference parameters. * Computes a quotient and a remainder, passed as reference parameters.
@ -140,7 +140,7 @@ enum // Values for m_flags
* @param q The quotient; will be NaN if divisor = 0 * @param q The quotient; will be NaN if divisor = 0
* @param r The remainder; will be 0 if divisor = 0 * @param r The remainder; will be 0 if divisor = 0
*/ */
void div (const QofInt128& d, QofInt128& q, QofInt128& r) noexcept; void div (const GncInt128& d, GncInt128& q, GncInt128& r) noexcept;
/** /**
* Explicit conversion to int64_t. * Explicit conversion to int64_t.
@ -188,7 +188,7 @@ enum // Values for m_flags
/** /**
* Fills a supplied buffer with a representation of the number in base 10. If * Fills a supplied buffer with a representation of the number in base 10. If
* the QofInt128 is overflowed or NaN it will contain the words "Overflow" or * the GncInt128 is overflowed or NaN it will contain the words "Overflow" or
* "NaN" respectively. * "NaN" respectively.
* *
* @param buf char[41], 39 digits plus sign and trailing 0. * @param buf char[41], 39 digits plus sign and trailing 0.
@ -196,59 +196,59 @@ enum // Values for m_flags
*/ */
char* asCharBufR(char* buf) const noexcept; char* asCharBufR(char* buf) const noexcept;
QofInt128 abs() const noexcept; GncInt128 abs() const noexcept;
QofInt128 operator-() const noexcept; GncInt128 operator-() const noexcept;
explicit operator bool() const noexcept; explicit operator bool() const noexcept;
QofInt128& operator++ () noexcept; GncInt128& operator++ () noexcept;
QofInt128& operator++ (int) noexcept; GncInt128& operator++ (int) noexcept;
QofInt128& operator-- () noexcept; GncInt128& operator-- () noexcept;
QofInt128& operator-- (int) noexcept; GncInt128& operator-- (int) noexcept;
QofInt128& operator<<= (uint i) noexcept; GncInt128& operator<<= (uint i) noexcept;
QofInt128& operator>>= (uint i) noexcept; GncInt128& operator>>= (uint i) noexcept;
QofInt128& operator+= (const QofInt128& b) noexcept; GncInt128& operator+= (const GncInt128& b) noexcept;
QofInt128& operator-= (const QofInt128& b) noexcept; GncInt128& operator-= (const GncInt128& b) noexcept;
QofInt128& operator*= (const QofInt128& b) noexcept; GncInt128& operator*= (const GncInt128& b) noexcept;
QofInt128& operator/= (const QofInt128& b) noexcept; GncInt128& operator/= (const GncInt128& b) noexcept;
QofInt128& operator%= (const QofInt128& b) noexcept; GncInt128& operator%= (const GncInt128& b) noexcept;
QofInt128& operator&= (const QofInt128& b) noexcept; GncInt128& operator&= (const GncInt128& b) noexcept;
QofInt128& operator|= (const QofInt128& b) noexcept; GncInt128& operator|= (const GncInt128& b) noexcept;
QofInt128& operator^= (const QofInt128& b) noexcept; GncInt128& operator^= (const GncInt128& b) noexcept;
}; };
static const QofInt128 k_qofInt128_Max {UINT64_MAX, UINT64_MAX, QofInt128::pos}; static const GncInt128 k_gncint128_Max {UINT64_MAX, UINT64_MAX, GncInt128::pos};
static const QofInt128 k_qofInt128_Min {UINT64_MAX, UINT64_MAX, QofInt128::neg}; static const GncInt128 k_gncint128_Min {UINT64_MAX, UINT64_MAX, GncInt128::neg};
QofInt128 operator+ (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator+ (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator- (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator- (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator* (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator* (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator/ (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator/ (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator% (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator% (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator& (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator& (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator| (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator| (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator^ (QofInt128 a, const QofInt128& b) noexcept; GncInt128 operator^ (GncInt128 a, const GncInt128& b) noexcept;
QofInt128 operator<< (QofInt128 a, uint b) noexcept; GncInt128 operator<< (GncInt128 a, uint b) noexcept;
QofInt128 operator>> (QofInt128 a, uint b) noexcept; GncInt128 operator>> (GncInt128 a, uint b) noexcept;
bool operator== (const QofInt128& a, const QofInt128& b) noexcept; bool operator== (const GncInt128& a, const GncInt128& b) noexcept;
bool operator!= (const QofInt128& a, const QofInt128& b) noexcept; bool operator!= (const GncInt128& a, const GncInt128& b) noexcept;
bool operator<= (const QofInt128& a, const QofInt128& b) noexcept; bool operator<= (const GncInt128& a, const GncInt128& b) noexcept;
bool operator>= (const QofInt128& a, const QofInt128& b) noexcept; bool operator>= (const GncInt128& a, const GncInt128& b) noexcept;
bool operator< (const QofInt128& a, const QofInt128& b) noexcept; bool operator< (const GncInt128& a, const GncInt128& b) noexcept;
bool operator> (const QofInt128& a, const QofInt128& b) noexcept; bool operator> (const GncInt128& a, const GncInt128& b) noexcept;
std::ostream& operator<< (std::ostream&, const QofInt128&) noexcept; std::ostream& operator<< (std::ostream&, const GncInt128&) noexcept;
/** Compute the greatest common denominator of two integers /** Compute the greatest common denominator of two integers
*/ */
QofInt128 gcd (int64_t a, int64_t b); GncInt128 gcd (int64_t a, int64_t b);
/** Compute the least common multiple of two integers /** Compute the least common multiple of two integers
*/ */
QofInt128 lcm (int64_t a, int64_t b); GncInt128 lcm (int64_t a, int64_t b);
#endif //QOFINT128_H #endif //GNCINT128_H
/** @} */ /** @} */

View File

@ -38,7 +38,6 @@ extern "C"
#endif #endif
#include "gnc-numeric.h" #include "gnc-numeric.h"
#include "qofint128.hpp"
#include "gnc-rational.hpp" #include "gnc-rational.hpp"
using GncNumeric = GncRational; using GncNumeric = GncRational;

View File

@ -47,7 +47,7 @@ GncRational::GncRational (gnc_numeric n) noexcept :
} }
} }
GncRational::GncRational (QofInt128 num, QofInt128 den) noexcept : GncRational::GncRational (GncInt128 num, GncInt128 den) noexcept :
m_num (num), m_den (den), m_error {} m_num (num), m_den (den), m_error {}
{ {
} }
@ -121,7 +121,7 @@ GncRational::div (GncRational b, GncDenom& d) noexcept
if (m_num.isBig() || m_den.isBig() || if (m_num.isBig() || m_den.isBig() ||
b.m_num.isBig() || b.m_den.isBig()) b.m_num.isBig() || b.m_den.isBig())
{ {
QofInt128 gcd = b.m_den.gcd(m_den); GncInt128 gcd = b.m_den.gcd(m_den);
b.m_den /= gcd; b.m_den /= gcd;
m_den /= gcd; m_den /= gcd;
} }
@ -141,7 +141,7 @@ GncRational::add (const GncRational& b, GncDenom& d) noexcept
m_error = b.m_error; m_error = b.m_error;
return *this; return *this;
} }
QofInt128 lcm = m_den.lcm (b.m_den); GncInt128 lcm = m_den.lcm (b.m_den);
m_num = m_num * lcm / m_den + b.m_num * lcm / b.m_den; m_num = m_num * lcm / m_den + b.m_num * lcm / b.m_den;
m_den = lcm; m_den = lcm;
round (d); round (d);
@ -163,7 +163,7 @@ GncRational::round (GncDenom& denom) noexcept
m_error = denom.m_error; m_error = denom.m_error;
return; return;
} }
QofInt128 new_den = denom.get(); GncInt128 new_den = denom.get();
if (new_den == 0) new_den = m_den; if (new_den == 0) new_den = m_den;
if (!(m_num.isBig() || new_den.isBig() )) if (!(m_num.isBig() || new_den.isBig() ))
{ {
@ -176,7 +176,7 @@ GncRational::round (GncDenom& denom) noexcept
return; return;
} }
} }
QofInt128 new_num {}, remainder {}; GncInt128 new_num {}, remainder {};
if (new_den.isNeg()) if (new_den.isNeg())
m_num.div(-new_den * m_den, new_num, remainder); m_num.div(-new_den * m_den, new_num, remainder);
else else
@ -198,7 +198,7 @@ GncRational::round (GncDenom& denom) noexcept
} }
/* First, try to reduce it */ /* First, try to reduce it */
QofInt128 gcd = new_num.gcd(new_den); GncInt128 gcd = new_num.gcd(new_den);
new_num /= gcd; new_num /= gcd;
new_den /= gcd; new_den /= gcd;
remainder /= gcd; remainder /= gcd;
@ -332,7 +332,7 @@ GncDenom::reduce (const GncRational& a) noexcept
break; break;
case DenomType::sigfigs: case DenomType::sigfigs:
QofInt128 val {}; GncInt128 val {};
if (a.m_num.abs() > a.m_den) if (a.m_num.abs() > a.m_den)
val = a.m_num.abs() / a.m_den; val = a.m_num.abs() / a.m_den;
else else

View File

@ -19,7 +19,7 @@
* Boston, MA 02110-1301, USA gnu@gnu.org * * Boston, MA 02110-1301, USA gnu@gnu.org *
* * * *
*******************************************************************/ *******************************************************************/
#include "qofint128.hpp" #include "gnc-int128.hpp"
#include "gnc-numeric.h" #include "gnc-numeric.h"
struct GncDenom; struct GncDenom;
@ -28,7 +28,7 @@ class GncRational
{ {
public: public:
GncRational (gnc_numeric n) noexcept; GncRational (gnc_numeric n) noexcept;
GncRational (QofInt128 num, QofInt128 den) noexcept; GncRational (GncInt128 num, GncInt128 den) noexcept;
/** Conversion operator; use static_cast<gnc_numeric>(foo). */ /** Conversion operator; use static_cast<gnc_numeric>(foo). */
operator gnc_numeric() const noexcept; operator gnc_numeric() const noexcept;
/** Make a new GncRational with the opposite sign. */ /** Make a new GncRational with the opposite sign. */
@ -46,8 +46,8 @@ public:
GncRational& sub(const GncRational& b, GncDenom& d) noexcept; GncRational& sub(const GncRational& b, GncDenom& d) noexcept;
QofInt128 m_num; GncInt128 m_num;
QofInt128 m_den; GncInt128 m_den;
GNCNumericErrorCode m_error; GNCNumericErrorCode m_error;
}; };
@ -55,7 +55,7 @@ struct GncDenom
{ {
GncDenom (GncRational& a, GncRational& b, int64_t spec, uint how) noexcept; GncDenom (GncRational& a, GncRational& b, int64_t spec, uint how) noexcept;
void reduce (const GncRational& a) noexcept; void reduce (const GncRational& a) noexcept;
QofInt128 get () const noexcept { return m_value; } GncInt128 get () const noexcept { return m_value; }
enum class RoundType : int enum class RoundType : int
{ {
@ -77,7 +77,7 @@ struct GncDenom
sigfigs = GNC_HOW_DENOM_SIGFIG, sigfigs = GNC_HOW_DENOM_SIGFIG,
}; };
QofInt128 m_value; GncInt128 m_value;
RoundType m_round; RoundType m_round;
DenomType m_type; DenomType m_type;
bool m_auto; bool m_auto;

View File

@ -34,20 +34,20 @@ check_PROGRAMS = \
TESTS = ${check_PROGRAMS} TESTS = ${check_PROGRAMS}
if WITH_GOOGLE_TEST if WITH_GOOGLE_TEST
test_qofint128_SOURCES = \ test_gnc_int128_SOURCES = \
$(top_srcdir)/${MODULEPATH}/qofint128.cpp \ $(top_srcdir)/${MODULEPATH}/gnc-int128.cpp \
${GTEST_ROOT}/src/gtest_main.cc \ ${GTEST_ROOT}/src/gtest_main.cc \
gtest-qofint128.cpp gtest-gnc-int128.cpp
test_qofint128_CPPFLAGS = \ test_gnc_int128_CPPFLAGS = \
-I${GTEST_HEADERS} \ -I${GTEST_HEADERS} \
${GLIB_CFLAGS} ${GLIB_CFLAGS}
test_qofint128_LDADD = \ test_gnc_int128_LDADD = \
${GLIB_LIBS} \ ${GLIB_LIBS} \
$(top_builddir)/src/test-core/libgtest.a $(top_builddir)/src/test-core/libgtest.a
check_PROGRAMS += test-qofint128 check_PROGRAMS += test-gnc-int128
endif endif
test_qofdir = ${GNC_LIBEXECDIR}/${MODULEPATH}/test test_qofdir = ${GNC_LIBEXECDIR}/${MODULEPATH}/test

View File

@ -1,5 +1,5 @@
/******************************************************************** /********************************************************************
* gtest-qofmath128.cpp -- unit tests for the QofInt128 class * * Gtest-gnc-int128.cpp -- unit tests for the GncInt128 class *
* Copyright (C) 2014 John Ralls <jralls@ceridwen.us> * * Copyright (C) 2014 John Ralls <jralls@ceridwen.us> *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
@ -22,11 +22,11 @@
*******************************************************************/ *******************************************************************/
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "../qofint128.hpp" #include "../gnc-int128.hpp"
TEST(qofint128_constructors, test_default_constructor) TEST(qofint128_constructors, test_default_constructor)
{ {
QofInt128 value {}; GncInt128 value {};
EXPECT_EQ (true, value.isZero()); EXPECT_EQ (true, value.isZero());
EXPECT_EQ (false, value.isNeg()); EXPECT_EQ (false, value.isNeg());
EXPECT_EQ (false, value.isBig()); EXPECT_EQ (false, value.isBig());
@ -36,28 +36,28 @@ TEST(qofint128_constructors, test_default_constructor)
TEST(qofint128_constructors, test_single_arg_constructor) TEST(qofint128_constructors, test_single_arg_constructor)
{ {
QofInt128 value1 (INT64_C(0)); GncInt128 value1 (INT64_C(0));
EXPECT_EQ (true, value1.isZero()); EXPECT_EQ (true, value1.isZero());
EXPECT_EQ (false, value1.isNeg()); EXPECT_EQ (false, value1.isNeg());
EXPECT_EQ (false, value1.isBig()); EXPECT_EQ (false, value1.isBig());
EXPECT_EQ (false, value1.isOverflow()); EXPECT_EQ (false, value1.isOverflow());
EXPECT_EQ (false, value1.isNan()); EXPECT_EQ (false, value1.isNan());
QofInt128 value2 (INT64_C(567894392130486208)); GncInt128 value2 (INT64_C(567894392130486208));
EXPECT_EQ (false, value2.isZero()); EXPECT_EQ (false, value2.isZero());
EXPECT_EQ (false, value2.isNeg()); EXPECT_EQ (false, value2.isNeg());
EXPECT_EQ (false, value2.isBig()); EXPECT_EQ (false, value2.isBig());
EXPECT_EQ (false, value2.isOverflow()); EXPECT_EQ (false, value2.isOverflow());
EXPECT_EQ (false, value2.isNan()); EXPECT_EQ (false, value2.isNan());
QofInt128 value3 (INT64_C(-567894392130486208)); GncInt128 value3 (INT64_C(-567894392130486208));
EXPECT_EQ (false, value3.isZero()); EXPECT_EQ (false, value3.isZero());
EXPECT_EQ (true, value3.isNeg()); EXPECT_EQ (true, value3.isNeg());
EXPECT_EQ (false, value3.isBig()); EXPECT_EQ (false, value3.isBig());
EXPECT_EQ (false, value3.isOverflow()); EXPECT_EQ (false, value3.isOverflow());
EXPECT_EQ (false, value3.isNan()); EXPECT_EQ (false, value3.isNan());
QofInt128 value4 (UINT64_C(13567894392130486208)); GncInt128 value4 (UINT64_C(13567894392130486208));
EXPECT_EQ (false, value4.isZero()); EXPECT_EQ (false, value4.isZero());
EXPECT_EQ (false, value4.isNeg()); EXPECT_EQ (false, value4.isNeg());
EXPECT_EQ (true, value4.isBig()); EXPECT_EQ (true, value4.isBig());
@ -67,35 +67,35 @@ TEST(qofint128_constructors, test_single_arg_constructor)
TEST(qofint128_constructors, test_double_arg_constructor) TEST(qofint128_constructors, test_double_arg_constructor)
{ {
QofInt128 value1 (INT64_C(0), INT64_C(0)); GncInt128 value1 (INT64_C(0), INT64_C(0));
EXPECT_EQ (true, value1.isZero()); EXPECT_EQ (true, value1.isZero());
EXPECT_EQ (false, value1.isNeg()); EXPECT_EQ (false, value1.isNeg());
EXPECT_EQ (false, value1.isBig()); EXPECT_EQ (false, value1.isBig());
EXPECT_EQ (false, value1.isOverflow()); EXPECT_EQ (false, value1.isOverflow());
EXPECT_EQ (false, value1.isNan()); EXPECT_EQ (false, value1.isNan());
QofInt128 value2 (INT64_C(0), INT64_C(567894392130486208)); GncInt128 value2 (INT64_C(0), INT64_C(567894392130486208));
EXPECT_EQ (false, value2.isZero()); EXPECT_EQ (false, value2.isZero());
EXPECT_EQ (false, value2.isNeg()); EXPECT_EQ (false, value2.isNeg());
EXPECT_EQ (false, value2.isBig()); EXPECT_EQ (false, value2.isBig());
EXPECT_EQ (false, value2.isOverflow()); EXPECT_EQ (false, value2.isOverflow());
EXPECT_EQ (false, value2.isNan()); EXPECT_EQ (false, value2.isNan());
QofInt128 value3 (INT64_C(567894392130486208), INT64_C(0)); GncInt128 value3 (INT64_C(567894392130486208), INT64_C(0));
EXPECT_EQ (false, value3.isZero()); EXPECT_EQ (false, value3.isZero());
EXPECT_EQ (false, value3.isNeg()); EXPECT_EQ (false, value3.isNeg());
EXPECT_EQ (true, value3.isBig()); EXPECT_EQ (true, value3.isBig());
EXPECT_EQ (false, value3.isOverflow()); EXPECT_EQ (false, value3.isOverflow());
EXPECT_EQ (false, value3.isNan()); EXPECT_EQ (false, value3.isNan());
QofInt128 value4 (INT64_C(567894392130486208), INT64_C(567894392130486208)); GncInt128 value4 (INT64_C(567894392130486208), INT64_C(567894392130486208));
EXPECT_EQ (false, value4.isZero()); EXPECT_EQ (false, value4.isZero());
EXPECT_EQ (false, value4.isNeg()); EXPECT_EQ (false, value4.isNeg());
EXPECT_EQ (true, value4.isBig()); EXPECT_EQ (true, value4.isBig());
EXPECT_EQ (false, value4.isOverflow()); EXPECT_EQ (false, value4.isOverflow());
EXPECT_EQ (false, value4.isNan()); EXPECT_EQ (false, value4.isNan());
QofInt128 value5 (INT64_C(567894392130486208), GncInt128 value5 (INT64_C(567894392130486208),
INT64_C(-567894392130486208)); INT64_C(-567894392130486208));
EXPECT_EQ (false, value5.isZero()); EXPECT_EQ (false, value5.isZero());
EXPECT_EQ (false, value5.isNeg()); EXPECT_EQ (false, value5.isNeg());
@ -103,7 +103,7 @@ TEST(qofint128_constructors, test_double_arg_constructor)
EXPECT_EQ (false, value5.isOverflow()); EXPECT_EQ (false, value5.isOverflow());
EXPECT_EQ (false, value5.isNan()); EXPECT_EQ (false, value5.isNan());
QofInt128 value6 (INT64_C(-567894392130486208), GncInt128 value6 (INT64_C(-567894392130486208),
INT64_C(567894392130486208)); INT64_C(567894392130486208));
EXPECT_EQ (false, value6.isZero()); EXPECT_EQ (false, value6.isZero());
EXPECT_EQ (true, value6.isNeg()); EXPECT_EQ (true, value6.isNeg());
@ -111,32 +111,32 @@ TEST(qofint128_constructors, test_double_arg_constructor)
EXPECT_EQ (false, value6.isOverflow()); EXPECT_EQ (false, value6.isOverflow());
EXPECT_EQ (false, value6.isNan()); EXPECT_EQ (false, value6.isNan());
QofInt128 value7 (UINT64_C(13567894392130486208), GncInt128 value7 (UINT64_C(13567894392130486208),
UINT64_C(13567894392130486208), QofInt128::pos); UINT64_C(13567894392130486208), GncInt128::pos);
EXPECT_EQ (false, value7.isZero()); EXPECT_EQ (false, value7.isZero());
EXPECT_EQ (false, value7.isNeg()); EXPECT_EQ (false, value7.isNeg());
EXPECT_EQ (true, value7.isBig()); EXPECT_EQ (true, value7.isBig());
EXPECT_EQ (false, value7.isOverflow()); EXPECT_EQ (false, value7.isOverflow());
EXPECT_EQ (false, value7.isNan()); EXPECT_EQ (false, value7.isNan());
QofInt128 value8 (UINT64_C(13567894392130486208), GncInt128 value8 (UINT64_C(13567894392130486208),
UINT64_C(13567894392130486208), QofInt128::neg); UINT64_C(13567894392130486208), GncInt128::neg);
EXPECT_EQ (false, value8.isZero()); EXPECT_EQ (false, value8.isZero());
EXPECT_EQ (true, value8.isNeg()); EXPECT_EQ (true, value8.isNeg());
EXPECT_EQ (true, value8.isBig()); EXPECT_EQ (true, value8.isBig());
EXPECT_EQ (false, value8.isOverflow()); EXPECT_EQ (false, value8.isOverflow());
EXPECT_EQ (false, value8.isNan()); EXPECT_EQ (false, value8.isNan());
QofInt128 value9 (UINT64_C(13567894392130486208), GncInt128 value9 (UINT64_C(13567894392130486208),
UINT64_C(13567894392130486208), QofInt128::overflow); UINT64_C(13567894392130486208), GncInt128::overflow);
EXPECT_EQ (false, value9.isZero()); EXPECT_EQ (false, value9.isZero());
EXPECT_EQ (false, value9.isNeg()); EXPECT_EQ (false, value9.isNeg());
EXPECT_EQ (true, value9.isBig()); EXPECT_EQ (true, value9.isBig());
EXPECT_EQ (true, value9.isOverflow()); EXPECT_EQ (true, value9.isOverflow());
EXPECT_EQ (false, value9.isNan()); EXPECT_EQ (false, value9.isNan());
QofInt128 value10 (UINT64_C(13567894392130486208), GncInt128 value10 (UINT64_C(13567894392130486208),
UINT64_C(13567894392130486208), QofInt128::NaN); UINT64_C(13567894392130486208), GncInt128::NaN);
EXPECT_EQ (false, value10.isZero()); EXPECT_EQ (false, value10.isZero());
EXPECT_EQ (false, value10.isNeg()); EXPECT_EQ (false, value10.isNeg());
EXPECT_EQ (true, value10.isBig()); EXPECT_EQ (true, value10.isBig());
@ -149,45 +149,45 @@ TEST(qofint128_functions, test_int_functions)
int64_t arg {INT64_C(567894392130486208)}; int64_t arg {INT64_C(567894392130486208)};
int64_t narg {INT64_C(-567894392130486208)}; int64_t narg {INT64_C(-567894392130486208)};
uint64_t uarg {UINT64_C(13567894392130486208)}; uint64_t uarg {UINT64_C(13567894392130486208)};
QofInt128 value1 (INT64_C(0), arg); GncInt128 value1 (INT64_C(0), arg);
EXPECT_EQ (arg, static_cast<int64_t>(value1)); EXPECT_EQ (arg, static_cast<int64_t>(value1));
EXPECT_EQ (static_cast<uint64_t>(arg), static_cast<uint64_t>(value1)); EXPECT_EQ (static_cast<uint64_t>(arg), static_cast<uint64_t>(value1));
QofInt128 value2 (UINT64_C(0), uarg); GncInt128 value2 (UINT64_C(0), uarg);
EXPECT_THROW (static_cast<int64_t>(value2), std::overflow_error); EXPECT_THROW (static_cast<int64_t>(value2), std::overflow_error);
EXPECT_EQ (uarg, static_cast<uint64_t>(value2)); EXPECT_EQ (uarg, static_cast<uint64_t>(value2));
QofInt128 value3 (UINT64_C(0), uarg, QofInt128::neg); GncInt128 value3 (UINT64_C(0), uarg, GncInt128::neg);
EXPECT_THROW (static_cast<int64_t>(value3), std::underflow_error); EXPECT_THROW (static_cast<int64_t>(value3), std::underflow_error);
EXPECT_THROW (static_cast<uint64_t>(value3), std::underflow_error); EXPECT_THROW (static_cast<uint64_t>(value3), std::underflow_error);
QofInt128 value4 (UINT64_C(0), uarg, QofInt128::overflow); GncInt128 value4 (UINT64_C(0), uarg, GncInt128::overflow);
EXPECT_THROW (static_cast<int64_t>(value4), std::overflow_error); EXPECT_THROW (static_cast<int64_t>(value4), std::overflow_error);
EXPECT_THROW (static_cast<uint64_t>(value4), std::overflow_error); EXPECT_THROW (static_cast<uint64_t>(value4), std::overflow_error);
QofInt128 value5 (UINT64_C(0), uarg, QofInt128::NaN); GncInt128 value5 (UINT64_C(0), uarg, GncInt128::NaN);
EXPECT_THROW (static_cast<int64_t>(value5), std::overflow_error); EXPECT_THROW (static_cast<int64_t>(value5), std::overflow_error);
EXPECT_THROW (static_cast<uint64_t>(value5), std::overflow_error); EXPECT_THROW (static_cast<uint64_t>(value5), std::overflow_error);
QofInt128 value6 (INT64_C(1), arg); GncInt128 value6 (INT64_C(1), arg);
EXPECT_THROW (static_cast<int64_t>(value6), std::overflow_error); EXPECT_THROW (static_cast<int64_t>(value6), std::overflow_error);
EXPECT_EQ (arg + (UINT64_C(0x1) << 63), static_cast<uint64_t>(value6)); EXPECT_EQ (arg + (UINT64_C(0x1) << 63), static_cast<uint64_t>(value6));
QofInt128 value7 (INT64_C(-1), arg); GncInt128 value7 (INT64_C(-1), arg);
EXPECT_EQ (-static_cast<int64_t>((UINT64_C(0x1) << 63) - arg), EXPECT_EQ (-static_cast<int64_t>((UINT64_C(0x1) << 63) - arg),
static_cast<int64_t>(value7)); static_cast<int64_t>(value7));
EXPECT_THROW (static_cast<uint64_t>(value7), std::underflow_error); EXPECT_THROW (static_cast<uint64_t>(value7), std::underflow_error);
QofInt128 value8 (INT64_C(0), narg); GncInt128 value8 (INT64_C(0), narg);
EXPECT_EQ (narg, static_cast<int64_t>(value8)); EXPECT_EQ (narg, static_cast<int64_t>(value8));
EXPECT_THROW (static_cast<uint64_t>(value8), std::underflow_error); EXPECT_THROW (static_cast<uint64_t>(value8), std::underflow_error);
QofInt128 value9 (INT64_C(1), narg); GncInt128 value9 (INT64_C(1), narg);
EXPECT_EQ (static_cast<int64_t>((UINT64_C(0x1) << 63) + narg), EXPECT_EQ (static_cast<int64_t>((UINT64_C(0x1) << 63) + narg),
static_cast<int64_t>(value9)); static_cast<int64_t>(value9));
EXPECT_EQ ((UINT64_C(0x1) << 63) + narg, static_cast<uint64_t>(value9)); EXPECT_EQ ((UINT64_C(0x1) << 63) + narg, static_cast<uint64_t>(value9));
QofInt128 value10 (INT64_C(-2), arg); GncInt128 value10 (INT64_C(-2), arg);
EXPECT_THROW (static_cast<int64_t>(value10), std::underflow_error); EXPECT_THROW (static_cast<int64_t>(value10), std::underflow_error);
EXPECT_THROW (static_cast<uint64_t>(value10), std::underflow_error); EXPECT_THROW (static_cast<uint64_t>(value10), std::underflow_error);
@ -200,23 +200,23 @@ TEST(qofint128_functions, test_compare)
int64_t sarg {INT64_C(567894392130486207)}; int64_t sarg {INT64_C(567894392130486207)};
int64_t nsarg {INT64_C(-567894392130486207)}; int64_t nsarg {INT64_C(-567894392130486207)};
QofInt128 big (barg); GncInt128 big (barg);
QofInt128 small (sarg); GncInt128 small (sarg);
QofInt128 neg_big (nbarg); GncInt128 neg_big (nbarg);
QofInt128 neg_small (nsarg); GncInt128 neg_small (nsarg);
QofInt128 really_big (barg, sarg); GncInt128 really_big (barg, sarg);
QofInt128 slightly_bigger (barg, barg); GncInt128 slightly_bigger (barg, barg);
QofInt128 not_as_big (sarg, barg); GncInt128 not_as_big (sarg, barg);
QofInt128 a_little_smaller (sarg, sarg); GncInt128 a_little_smaller (sarg, sarg);
QofInt128 neg_really_big (barg, sarg, QofInt128::neg); GncInt128 neg_really_big (barg, sarg, GncInt128::neg);
QofInt128 neg_slightly_bigger (barg, barg, QofInt128::neg); GncInt128 neg_slightly_bigger (barg, barg, GncInt128::neg);
QofInt128 neg_not_as_big (sarg, barg, QofInt128::neg); GncInt128 neg_not_as_big (sarg, barg, GncInt128::neg);
QofInt128 neg_a_little_smaller (sarg, sarg, QofInt128::neg); GncInt128 neg_a_little_smaller (sarg, sarg, GncInt128::neg);
QofInt128 overflowed (INT64_C(0), INT64_C(0), QofInt128::overflow); GncInt128 overflowed (INT64_C(0), INT64_C(0), GncInt128::overflow);
QofInt128 not_a_number (INT64_C(0), INT64_C(0), QofInt128::NaN); GncInt128 not_a_number (INT64_C(0), INT64_C(0), GncInt128::NaN);
EXPECT_EQ (-1, overflowed.cmp (big)); EXPECT_EQ (-1, overflowed.cmp (big));
EXPECT_EQ (-1, not_a_number.cmp (big)); EXPECT_EQ (-1, not_a_number.cmp (big));
@ -250,9 +250,9 @@ TEST(qofint128_functions, test_compare)
EXPECT_EQ (-1, neg_not_as_big.cmp(neg_a_little_smaller)); EXPECT_EQ (-1, neg_not_as_big.cmp(neg_a_little_smaller));
EXPECT_EQ (-1, neg_really_big.cmp(neg_a_little_smaller)); EXPECT_EQ (-1, neg_really_big.cmp(neg_a_little_smaller));
EXPECT_EQ (0, neg_really_big.cmp(QofInt128(barg, sarg, QofInt128::neg))); EXPECT_EQ (0, neg_really_big.cmp(GncInt128(barg, sarg, GncInt128::neg)));
EXPECT_EQ (0, really_big.cmp(QofInt128(barg, sarg))); EXPECT_EQ (0, really_big.cmp(GncInt128(barg, sarg)));
EXPECT_EQ (0, really_big.cmp(QofInt128(barg, sarg, QofInt128::pos))); EXPECT_EQ (0, really_big.cmp(GncInt128(barg, sarg, GncInt128::pos)));
EXPECT_EQ (0, really_big.cmp(-neg_really_big)); EXPECT_EQ (0, really_big.cmp(-neg_really_big));
EXPECT_EQ (0, neg_really_big.cmp(-really_big)); EXPECT_EQ (0, neg_really_big.cmp(-really_big));
@ -264,15 +264,15 @@ TEST(qofint128_functions, stream_output)
int64_t sarg {INT64_C(567894392130486207)}; int64_t sarg {INT64_C(567894392130486207)};
int64_t nsarg {INT64_C(-567894392130486207)}; int64_t nsarg {INT64_C(-567894392130486207)};
QofInt128 small (sarg); GncInt128 small (sarg);
QofInt128 neg_small (nsarg); GncInt128 neg_small (nsarg);
QofInt128 really_big (barg, sarg); GncInt128 really_big (barg, sarg);
QofInt128 neg_really_big (barg, sarg, QofInt128::neg); GncInt128 neg_really_big (barg, sarg, GncInt128::neg);
QofInt128 overflowed (INT64_C(0), INT64_C(0), QofInt128::overflow); GncInt128 overflowed (INT64_C(0), INT64_C(0), GncInt128::overflow);
QofInt128 not_a_number (INT64_C(0), INT64_C(0), QofInt128::NaN); GncInt128 not_a_number (INT64_C(0), INT64_C(0), GncInt128::NaN);
QofInt128 boundary_value (UINT64_C(1), UINT64_MAX); GncInt128 boundary_value (UINT64_C(1), UINT64_MAX);
static const uint8_t char_buf_size {41}; static const uint8_t char_buf_size {41};
char buf[char_buf_size] {}; char buf[char_buf_size] {};
@ -297,24 +297,24 @@ TEST(qofint128_functions, add_and_subtract)
int64_t sarg {INT64_C(4344522355275710400)}; int64_t sarg {INT64_C(4344522355275710400)};
uint64_t uarg {UINT64_C(13567894392130486208)}; uint64_t uarg {UINT64_C(13567894392130486208)};
QofInt128 smallest (sarg + 100); GncInt128 smallest (sarg + 100);
QofInt128 smaller (barg + 500); GncInt128 smaller (barg + 500);
QofInt128 small (uarg); GncInt128 small (uarg);
QofInt128 big (sarg, barg); GncInt128 big (sarg, barg);
QofInt128 bigger (static_cast<uint64_t>(barg), uarg); GncInt128 bigger (static_cast<uint64_t>(barg), uarg);
QofInt128 biggest (uarg, static_cast<uint64_t>(barg)); GncInt128 biggest (uarg, static_cast<uint64_t>(barg));
QofInt128 nsmall (UINT64_C(0), uarg, QofInt128::neg); GncInt128 nsmall (UINT64_C(0), uarg, GncInt128::neg);
EXPECT_EQ (QofInt128(INT64_C(2), INT64_C(499)), small += smaller); EXPECT_EQ (GncInt128(INT64_C(2), INT64_C(499)), small += smaller);
EXPECT_EQ (QofInt128(INT64_C(2), INT64_C(499), QofInt128::neg), EXPECT_EQ (GncInt128(INT64_C(2), INT64_C(499), GncInt128::neg),
nsmall -= smaller); nsmall -= smaller);
EXPECT_EQ (QofInt128(uarg), small -= smaller); EXPECT_EQ (GncInt128(uarg), small -= smaller);
EXPECT_EQ (QofInt128(static_cast<uint64_t>(barg + sarg/2), UINT64_MAX), EXPECT_EQ (GncInt128(static_cast<uint64_t>(barg + sarg/2), UINT64_MAX),
bigger += big); bigger += big);
EXPECT_EQ (QofInt128(static_cast<uint64_t>(barg), uarg), bigger -= big); EXPECT_EQ (GncInt128(static_cast<uint64_t>(barg), uarg), bigger -= big);
bigger += biggest; bigger += biggest;
EXPECT_EQ (QofInt128(UINT64_MAX, UINT64_MAX), bigger); EXPECT_EQ (GncInt128(UINT64_MAX, UINT64_MAX), bigger);
bigger += smallest; bigger += smallest;
EXPECT_TRUE (bigger.isOverflow()); EXPECT_TRUE (bigger.isOverflow());
bigger -= biggest; bigger -= biggest;
@ -327,17 +327,17 @@ TEST(qofint128_functions, multiply)
int64_t sarg {INT64_C(4344522355275710400)}; int64_t sarg {INT64_C(4344522355275710400)};
uint64_t uarg {UINT64_C(13567894392130486208)}; uint64_t uarg {UINT64_C(13567894392130486208)};
QofInt128 smallest (sarg); GncInt128 smallest (sarg);
QofInt128 smaller (barg); GncInt128 smaller (barg);
QofInt128 small (uarg); GncInt128 small (uarg);
QofInt128 big (sarg, barg); GncInt128 big (sarg, barg);
QofInt128 bigger (static_cast<uint64_t>(barg), uarg); GncInt128 bigger (static_cast<uint64_t>(barg), uarg);
small *= big; small *= big;
EXPECT_TRUE (small.isOverflow()); EXPECT_TRUE (small.isOverflow());
big *= bigger; big *= bigger;
EXPECT_TRUE (big.isOverflow()); EXPECT_TRUE (big.isOverflow());
EXPECT_EQ (QofInt128(UINT64_C(1149052180967758316), UINT64_C(6323251814974894144)), smallest *= smaller); EXPECT_EQ (GncInt128(UINT64_C(1149052180967758316), UINT64_C(6323251814974894144)), smallest *= smaller);
EXPECT_FALSE (smallest.isOverflow()); EXPECT_FALSE (smallest.isOverflow());
} }
@ -348,39 +348,39 @@ TEST(qofint128_functions, divide)
int64_t sarg {INT64_C(4344522355275710400)}; int64_t sarg {INT64_C(4344522355275710400)};
uint64_t uarg {UINT64_C(13567894392130486208)}; uint64_t uarg {UINT64_C(13567894392130486208)};
QofInt128 zero (INT64_C(0)); GncInt128 zero (INT64_C(0));
QofInt128 one (INT64_C(1)); GncInt128 one (INT64_C(1));
QofInt128 two (INT64_C(2)); GncInt128 two (INT64_C(2));
QofInt128 smallest (sarg); GncInt128 smallest (sarg);
QofInt128 smaller (barg); GncInt128 smaller (barg);
QofInt128 small (uarg); GncInt128 small (uarg);
QofInt128 big (sarg, barg); GncInt128 big (sarg, barg);
QofInt128 bigger (static_cast<uint64_t>(barg), uarg); GncInt128 bigger (static_cast<uint64_t>(barg), uarg);
QofInt128 nsmall = -small; GncInt128 nsmall = -small;
QofInt128 nbig = -bigger; GncInt128 nbig = -bigger;
EXPECT_EQ (QofInt128(INT64_C(0)), zero /= smallest); EXPECT_EQ (GncInt128(INT64_C(0)), zero /= smallest);
EXPECT_EQ (QofInt128(INT64_C(0)), zero %= smallest); EXPECT_EQ (GncInt128(INT64_C(0)), zero %= smallest);
smallest /= zero; smallest /= zero;
EXPECT_TRUE (smallest.isNan()); EXPECT_TRUE (smallest.isNan());
QofInt128 r {}, q {}; GncInt128 r {}, q {};
small.div (smaller, q, r); small.div (smaller, q, r);
EXPECT_EQ (two, q); EXPECT_EQ (two, q);
EXPECT_EQ (QofInt128(INT64_C(3810195028972355394)), r); EXPECT_EQ (GncInt128(INT64_C(3810195028972355394)), r);
small.div (-smaller, q, r); small.div (-smaller, q, r);
EXPECT_EQ (-two, q); EXPECT_EQ (-two, q);
EXPECT_EQ (QofInt128(INT64_C(3810195028972355394)), r); EXPECT_EQ (GncInt128(INT64_C(3810195028972355394)), r);
nsmall.div (smaller, q, r); nsmall.div (smaller, q, r);
EXPECT_EQ (-two, q); EXPECT_EQ (-two, q);
EXPECT_EQ (QofInt128(INT64_C(3810195028972355394)), r); EXPECT_EQ (GncInt128(INT64_C(3810195028972355394)), r);
nsmall.div (-smaller, q, r); nsmall.div (-smaller, q, r);
EXPECT_EQ (two, q); EXPECT_EQ (two, q);
EXPECT_EQ (QofInt128(INT64_C(3810195028972355394)), r); EXPECT_EQ (GncInt128(INT64_C(3810195028972355394)), r);
bigger.div (bigger, q, r); bigger.div (bigger, q, r);
EXPECT_EQ (one, q); EXPECT_EQ (one, q);
@ -391,27 +391,27 @@ TEST(qofint128_functions, divide)
EXPECT_EQ (zero, r); EXPECT_EQ (zero, r);
big.div (smaller, q, r); big.div (smaller, q, r);
EXPECT_EQ (QofInt128(INT64_C(8213236443097627766)), q); EXPECT_EQ (GncInt128(INT64_C(8213236443097627766)), q);
EXPECT_EQ (QofInt128(INT64_C(3162679692459777845)), r); EXPECT_EQ (GncInt128(INT64_C(3162679692459777845)), r);
bigger.div (big, q, r); bigger.div (big, q, r);
EXPECT_EQ (two, q); EXPECT_EQ (two, q);
EXPECT_EQ (QofInt128(UINT64_C(534327326303355007), EXPECT_EQ (GncInt128(UINT64_C(534327326303355007),
UINT64_C(3810195028972355394)), r); UINT64_C(3810195028972355394)), r);
bigger.div (-big, q, r); bigger.div (-big, q, r);
EXPECT_EQ (-two, q); EXPECT_EQ (-two, q);
EXPECT_EQ (QofInt128(UINT64_C(534327326303355007), EXPECT_EQ (GncInt128(UINT64_C(534327326303355007),
UINT64_C(3810195028972355394)), r); UINT64_C(3810195028972355394)), r);
nbig.div (-big, q, r); nbig.div (-big, q, r);
EXPECT_EQ (two, q); EXPECT_EQ (two, q);
EXPECT_EQ (QofInt128(UINT64_C(534327326303355007), EXPECT_EQ (GncInt128(UINT64_C(534327326303355007),
UINT64_C(3810195028972355394)), r); UINT64_C(3810195028972355394)), r);
nbig.div (-big, q, r); nbig.div (-big, q, r);
EXPECT_EQ (two, q); EXPECT_EQ (two, q);
EXPECT_EQ (QofInt128(UINT64_C(534327326303355007), EXPECT_EQ (GncInt128(UINT64_C(534327326303355007),
UINT64_C(3810195028972355394)), r); UINT64_C(3810195028972355394)), r);
big.div (bigger, q, r); big.div (bigger, q, r);
@ -428,13 +428,13 @@ TEST(qofint128_functions, GCD)
int64_t sarg {INT64_C(4344522355275710401)}; int64_t sarg {INT64_C(4344522355275710401)};
uint64_t uarg {UINT64_C(13567894392130486208)}; uint64_t uarg {UINT64_C(13567894392130486208)};
QofInt128 one (INT64_C(1)); GncInt128 one (INT64_C(1));
QofInt128 smallest (sarg); GncInt128 smallest (sarg);
QofInt128 smaller (barg); GncInt128 smaller (barg);
QofInt128 small (uarg); GncInt128 small (uarg);
QofInt128 big = smaller * smallest; GncInt128 big = smaller * smallest;
QofInt128 bigger = small * smaller; GncInt128 bigger = small * smaller;
EXPECT_EQ (smaller, big.gcd(smaller)); EXPECT_EQ (smaller, big.gcd(smaller));
EXPECT_EQ (smallest, big.gcd(smallest)); EXPECT_EQ (smallest, big.gcd(smallest));
@ -450,17 +450,17 @@ TEST(qofint128_functions, pow)
int64_t sarg {INT64_C(53309)}; int64_t sarg {INT64_C(53309)};
int64_t barg {INT64_C(4878849681579065407)}; int64_t barg {INT64_C(4878849681579065407)};
QofInt128 little (sarg); GncInt128 little (sarg);
QofInt128 big (barg); GncInt128 big (barg);
auto minus = -little; auto minus = -little;
EXPECT_EQ (QofInt128(1), little.pow(0)); EXPECT_EQ (GncInt128(1), little.pow(0));
EXPECT_EQ (QofInt128(0), QofInt128(0).pow(123)); EXPECT_EQ (GncInt128(0), GncInt128(0).pow(123));
EXPECT_EQ (big * big, big.pow(2)); EXPECT_EQ (big * big, big.pow(2));
EXPECT_EQ (QofInt128(UINT64_C(66326033898754), EXPECT_EQ (GncInt128(UINT64_C(66326033898754),
UINT64_C(10251549987585143605)), little.pow(7)); UINT64_C(10251549987585143605)), little.pow(7));
EXPECT_EQ (QofInt128(UINT64_C(66326033898754), EXPECT_EQ (GncInt128(UINT64_C(66326033898754),
UINT64_C(10251549987585143605), QofInt128::neg), UINT64_C(10251549987585143605), GncInt128::neg),
minus.pow(7)); minus.pow(7));
auto over = minus.pow(9); auto over = minus.pow(9);
EXPECT_TRUE(over.isOverflow()); EXPECT_TRUE(over.isOverflow());