X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Farbint.h;h=468785f315dd81b2311af6bfb77959cd81430672;hp=06008e072fcb3e5df96e303ca17be7b08f3c26a0;hb=dfd021b1505fb3924ae103d8aa27c6200d6ec3fd;hpb=924cb525f587c58440c43bcae6ccfd9b2e41c99c diff --git a/src/arbint.h b/src/arbint.h index 06008e0..468785f 100644 --- a/src/arbint.h +++ b/src/arbint.h @@ -25,7 +25,7 @@ namespace IPDF int64_t AsDigit() const { - int64_t digit = (m_digits.size() == 1) ? m_digits[0] : 0x7FFFFFFFFFFFFFFF; + int64_t digit = (m_digits.size() == 1) ? m_digits[0] : 0xBADF00D; return (m_sign) ? -digit : digit; } @@ -68,6 +68,13 @@ namespace IPDF return a; } + inline Arbint operator-() const + { + Arbint a(*this); + a.m_sign = !a.m_sign; + return a; + } + inline Arbint operator*(const Arbint & mul) const { Arbint a(*this); @@ -99,6 +106,7 @@ namespace IPDF bool operator==(const Arbint & equ) const; bool operator<(const Arbint & less) const; + inline bool operator!=(const Arbint & equ) const { @@ -130,11 +138,11 @@ namespace IPDF return result; } bool IsZero() const; - - inline operator double() const + + inline operator double() const { double acc = 0; - for(int i = m_digits.size()-1; i >= 0; --i) + for (int i = m_digits.size()-1; i >= 0; --i) { acc += (double)m_digits[i]; acc *= (double)UINT64_MAX + 1.0; @@ -153,6 +161,8 @@ namespace IPDF Arbint & AddBasic(const Arbint & add); Arbint & SubBasic(const Arbint & sub); + void GrowDigit(digit_t new_msd); // add a new most significant digit + bool GetBit(unsigned i) const; void BitClear(unsigned i); void BitSet(unsigned i);