summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
eaebb5a)
Well I suppose this shouldn't have been totally unexpected...
all : $(BIN)
single : DEF = -DREAL=0
all : $(BIN)
single : DEF = -DREAL=0
//TODO: Optimise?
remainder = *this;
result = 0L;
//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());
{
//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
{
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;}
}
inline bool Sign() const {return m_sign;}
+ //inline operator double() const {return double(AsDigit());}
+ inline operator digit_t() const {return AsDigit();}
+ //inline operator int() const {return int(AsDigit());}
+
unsigned Shrink();
private:
unsigned Shrink();
private:
- while ((g = big % small) > 0)
+ while ((g = big % small) > T(0))
{
big = small;
small = g;
{
big = small;
small = g;
- T g = gcd(llabs(P),llabs(Q));
+ T g = gcd(T(llabs(P)),T(llabs(Q)));
Rational operator+(const Rational & r) const
{
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
{
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;
}
result.CheckAccuracy(ToDouble() - r.ToDouble(),"-");
return result;
}
"double",
"long double",
"single [fast2sum]", //TODO REMOVE DOESN'T DO ANYTHING USEFUL
"double",
"long double",
"single [fast2sum]", //TODO REMOVE DOESN'T DO ANYTHING USEFUL
+ "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_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!"
#ifndef REAL
#error "REAL was not defined!"
#include "rational.h"
#endif //REAL
#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[];
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
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();}
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
#else
#error "Type of Real unspecified."
#endif //REAL