From: Sam Moore Date: Sun, 6 Jul 2014 12:30:40 +0000 (+0800) Subject: Arbint now does sign in division correctly X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=ba945308b9273fcd420b3d4f1395b44bd6625929 Arbint now does sign in division correctly The tester still sometimes picks up a fith Rational /= operation though. --- diff --git a/src/arbint.cpp b/src/arbint.cpp index 59e2252..4bde578 100644 --- a/src/arbint.cpp +++ b/src/arbint.cpp @@ -127,6 +127,7 @@ void Arbint::Division(const Arbint & div, Arbint & result, Arbint & remainder) c result.BitSet(i); } } + result.m_sign = !(m_sign == div.m_sign); } Arbint & Arbint::operator+=(const Arbint & add) @@ -265,7 +266,7 @@ Arbint & Arbint::operator>>=(unsigned amount) if (whole >= old_size) { - m_digits.resize(1); + m_digits.resize(1,0L); m_digits[0] = 0L; return *this; } diff --git a/src/rational.h b/src/rational.h index e74567d..53f7d02 100644 --- a/src/rational.h +++ b/src/rational.h @@ -73,10 +73,6 @@ struct Rational Rational(double d=0) : P(d*1e6), Q(1e6) // Possibly the worst thing ever... { Simplify(); - //if (!CheckAccuracy(d, "Construct from double")) - { - //Fatal("Bwah bwah :("); - } } Rational(const T & _P, const T & _Q) : P(_P), Q(_Q) diff --git a/src/tests/realops.cpp b/src/tests/realops.cpp index 8076a14..400ce86 100644 --- a/src/tests/realops.cpp +++ b/src/tests/realops.cpp @@ -6,9 +6,13 @@ using namespace IPDF; #define TEST_CASES 100 -bool NotEqual(double a, double b, double threshold=1e-2) +static double g_totalerror = 0; + +bool NotEqual(double a, double b, double threshold=1e-1) { - return (fabs(a-b) > threshold); + double error = (fabs(a-b) > threshold); + g_totalerror += error; + return (error > threshold); } int main(int argc, char ** argv) @@ -117,5 +121,6 @@ int main(int argc, char ** argv) } } Debug("Completed %u test cases with total of %u operations, %u failures", TEST_CASES, 12*TEST_CASES, failures); + Debug("Total accumulated difference between Real and Double operations was %f", g_totalerror); }