Well I suppose this shouldn't have been totally unexpected...
BIN = ../bin/ipdf
-all : DEF = -DREAL=4
+all : DEF = -DREAL=1
all : $(BIN)
single : DEF = -DREAL=0
//TODO: Optimise?
remainder = *this;
result = 0L;
- while ((remainder -= div) > 0L)
+ while ((remainder -= div) > Arbint(0L))
{
//Debug("Remainder %c%s", remainder.SignChar(), remainder.DigitStr().c_str());
//Debug("Result %c%s + 1", result.SignChar(), result.DigitStr().c_str());
digit_t AsDigit() const
{
- return (m_sign) ? -m_digits[0] : m_digits[0];
+ digit_t digit = (m_digits.size() == 1) ? m_digits[0] : 0xFFFFFFFFFFFFFFFF;
+ return (m_sign) ? -digit : digit;
}
inline bool Sign() const {return m_sign;}
bool IsZero() const;
+ //inline operator double() const {return double(AsDigit());}
+ inline operator digit_t() const {return AsDigit();}
+ //inline operator int() const {return int(AsDigit());}
+
unsigned Shrink();
private:
big = q;
small = p;
}
- if (small == 0)
+ if (small == T(0))
return g;
- while ((g = big % small) > 0)
+ while ((g = big % small) > T(0))
{
big = small;
small = g;
void Simplify()
{
- if (Q < 0)
+ if (Q < T(0))
{
P = -P;
Q = -Q;
}
- if (P == 0)
+ if (P == T(0))
{
- Q = 1;
+ Q = T(1);
return;
}
- T g = gcd(llabs(P),llabs(Q));
+ T g = gcd(T(llabs(P)),T(llabs(Q)));
P /= g;
Q /= g;
}
Rational operator+(const Rational & r) const
{
- Rational result = (r.P == 0) ? Rational(P,Q) : Rational(P*r.Q + r.P*Q, Q*r.Q);
+ Rational result = (r.P == T(0)) ? Rational(P,Q) : Rational(P*r.Q + r.P*Q, Q*r.Q);
result.CheckAccuracy(ToDouble() + r.ToDouble(),"+");
return result;
}
Rational operator-(const Rational & r) const
{
- Rational result = (r.P == 0) ? Rational(P,Q) : Rational(P*r.Q - r.P*Q, Q*r.Q);
+ Rational result = (r.P == T(0)) ? Rational(P,Q) : Rational(P*r.Q - r.P*Q, Q*r.Q);
result.CheckAccuracy(ToDouble() - r.ToDouble(),"-");
return result;
}
}
+
}
#endif //_RATIONAL_H
"double",
"long double",
"single [fast2sum]", //TODO REMOVE DOESN'T DO ANYTHING USEFUL
- "Rational<int64_t>"
+ "Rational<int64_t>",
+ "Rational<Arbint>"
};
}
#define REAL_LONG_DOUBLE 2
#define REAL_SINGLE_FAST2SUM 3 //TODO: Remove, is FITH
#define REAL_RATIONAL 4
+#define REAL_RATIONAL_ARBINT 5
#ifndef REAL
#error "REAL was not defined!"
#include "rational.h"
#endif //REAL
+#if REAL == REAL_RATIONAL_ARBINT
+ #include "rational.h"
+ #include "arbint.h"
+#endif //REAL
+
namespace IPDF
{
extern const char * g_real_name[];
inline float Float(const Real & r) {return r.m_value;}
inline double Double(const Real & r) {return r.m_value;}
#elif REAL == REAL_RATIONAL
-
+
typedef Rational<int64_t> Real;
inline float Float(const Real & r) {return (float)r.ToDouble();}
inline double Double(const Real & r) {return r.ToDouble();}
+#elif REAL == REAL_RATIONAL_ARBINT
+ typedef Rational<Arbint> Real;
+ inline float Float(const Real & r) {return (float)r.ToDouble();}
+ inline double Double(const Real & r) {return r.ToDouble();}
+ inline Rational<Arbint> pow(const Rational<Arbint> & a, const Rational<Arbint> & b)
+ {
+ Arbint P(std::pow(static_cast<double>(a.P), b.ToDouble()));
+ Arbint Q(std::pow(static_cast<double>(a.Q), b.ToDouble()));
+ return Rational<Arbint>(P,Q);
+ }
#else
#error "Type of Real unspecified."
#endif //REAL