X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Farbint.h;h=06008e072fcb3e5df96e303ca17be7b08f3c26a0;hp=0f047c9d26aad2d35d6a1928d28a54f5d27134c9;hb=924cb525f587c58440c43bcae6ccfd9b2e41c99c;hpb=ba945308b9273fcd420b3d4f1395b44bd6625929 diff --git a/src/arbint.h b/src/arbint.h index 0f047c9..06008e0 100644 --- a/src/arbint.h +++ b/src/arbint.h @@ -23,7 +23,7 @@ namespace IPDF virtual ~Arbint() {} Arbint(const Arbint & cpy); - int64_t AsDigit() const + int64_t AsDigit() const { int64_t digit = (m_digits.size() == 1) ? m_digits[0] : 0x7FFFFFFFFFFFFFFF; return (m_sign) ? -digit : digit; @@ -60,6 +60,13 @@ namespace IPDF a -= add; return a; } + + inline Arbint operator-() + { + Arbint a(*this); + a.m_sign = !a.m_sign; + return a; + } inline Arbint operator*(const Arbint & mul) const { @@ -124,7 +131,17 @@ namespace IPDF } bool IsZero() const; - //inline operator double() const {return double(AsDigit());} + inline operator double() const + { + double acc = 0; + for(int i = m_digits.size()-1; i >= 0; --i) + { + acc += (double)m_digits[i]; + acc *= (double)UINT64_MAX + 1.0; + } + if (m_sign) acc *= -1; + return acc; + } inline operator int64_t() const {return AsDigit();} //inline operator int() const {return int(AsDigit());}