From: Sam Moore Date: Sat, 5 Jul 2014 07:52:38 +0000 (+0800) Subject: It compiles... and runs with FPS of zero X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3ab3475a54c82cb9f5e0b1dbb88035f341b92d49;p=ipdf%2Fcode.git It compiles... and runs with FPS of zero Well I suppose this shouldn't have been totally unexpected... --- diff --git a/src/Makefile b/src/Makefile index 9dfda08..94d6f1f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -30,7 +30,7 @@ RM = rm -f BIN = ../bin/ipdf -all : DEF = -DREAL=4 +all : DEF = -DREAL=1 all : $(BIN) single : DEF = -DREAL=0 diff --git a/src/arbint.cpp b/src/arbint.cpp index 3a1757b..d61dabc 100644 --- a/src/arbint.cpp +++ b/src/arbint.cpp @@ -111,7 +111,7 @@ void Arbint::Division(const Arbint & div, Arbint & result, Arbint & remainder) c //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()); diff --git a/src/arbint.h b/src/arbint.h index f137796..12f8302 100644 --- a/src/arbint.h +++ b/src/arbint.h @@ -25,7 +25,8 @@ namespace IPDF 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;} @@ -109,6 +110,10 @@ namespace IPDF 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: diff --git a/src/rational.h b/src/rational.h index 9fe8f1f..ce1a767 100644 --- a/src/rational.h +++ b/src/rational.h @@ -37,9 +37,9 @@ T gcd(const T & p, const T & q) 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; @@ -69,17 +69,17 @@ struct Rational 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; } @@ -99,13 +99,13 @@ struct Rational 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; } @@ -171,6 +171,7 @@ inline Rational pow(const Rational & a, const Rational" + "Rational", + "Rational" }; } diff --git a/src/real.h b/src/real.h index ab90384..8dea953 100644 --- a/src/real.h +++ b/src/real.h @@ -9,6 +9,7 @@ #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!" @@ -22,6 +23,11 @@ #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[]; @@ -37,10 +43,20 @@ namespace IPDF 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 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 Real; + inline float Float(const Real & r) {return (float)r.ToDouble();} + inline double Double(const Real & r) {return r.ToDouble();} + inline Rational pow(const Rational & a, const Rational & b) + { + Arbint P(std::pow(static_cast(a.P), b.ToDouble())); + Arbint Q(std::pow(static_cast(a.Q), b.ToDouble())); + return Rational(P,Q); + } #else #error "Type of Real unspecified." #endif //REAL