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;
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
{
}
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());}
template <class T> T Tabs(const T & a)
{
- return llabs(a);
+ return abs(a);
}
+template <> Arbint Tabs(const Arbint & a);
/* Recursive version of GCD
Q = T(1);
return;
}
+ if (P == Q)
+ {
+ P = Q = T(1);
+ return;
+ }
+
T g = gcd(Tabs(P), Tabs(Q));
//Debug("Got gcd!");
P /= g;
//Rational operator*(const Rational & r) const {return Rational(ToDouble()*r.ToDouble());}
//Rational operator/(const Rational & r) const {return Rational(ToDouble()/r.ToDouble());}
- Rational & operator=(const Rational & r) {P = r.P; Q = r.Q; return *this;}
+ Rational & operator=(const Rational & r) {P = r.P; Q = r.Q; Simplify(); return *this;}
Rational & operator+=(const Rational & r) {this->operator=(*this+r); return *this;}
Rational & operator-=(const Rational & r) {this->operator=(*this-r); return *this;}
Rational & operator*=(const Rational & r) {this->operator=(*this*r); return *this;}