9 static double g_totalerror = 0;
11 bool NotEqual(double a, double b, double threshold=1e-1)
13 double error = (fabs(a-b) > threshold);
14 g_totalerror += error;
15 return (error > threshold);
18 int main(int argc, char ** argv)
22 unsigned failures = 0;
23 for (unsigned i = 0; i < TEST_CASES; ++i)
25 double da = (double)(rand()%100 + 1) / (double)(rand()%100 + 1);
26 double db = (double)(rand()%100 + 1) / (double)(rand()%100 + 1);
37 unsigned old_failures = failures;
38 if (NotEqual(Double(a), Double(aa)))
41 Warn("a != Real(a); %f vs %f", Double(a), Double(aa));
43 if (NotEqual(Double(b), Double(bb)))
46 Warn("b != Real(b); %f vs %f", Double(b), Double(bb));
49 if (NotEqual(Double(a), da))
52 Warn("a != da; %f vs %f", Double(a), da);
54 if (NotEqual(Double(b), db))
57 Warn("b != db; %f vs %f", Double(b), db);
59 if (NotEqual(Double(a+b), da+db))
62 Warn("a + b = %f should be %f", Double(a+b), da+db);
64 if (NotEqual(Double(a-b), da-db))
67 Warn("a - b = %f should be %f", Double(a-b), da-db);
69 if (NotEqual(Double(a*b), da*db))
72 Warn("a * b = %f should be %f", Double(a*b), da*db);
74 if (NotEqual(Double(a/b), da/db))
77 Warn("a / b = %f should be %f", Double(a/b), da/db);
80 if (NotEqual(Double(a), da))
83 Warn("a has changed after +-*/ from %f to %f", da, Double(a));
85 if (NotEqual(Double(b), db))
88 Warn("b has changed after +-*/ from %f to %f", db, Double(b));
91 if (NotEqual(Double(a+=b), da+=db))
94 Warn("a += b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
97 if (NotEqual(Double(a-=b), da-=db))
100 Warn("a -= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
103 if (NotEqual(Double(a*=b), da*=db))
106 Warn("a *= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
109 if (NotEqual(Double(a/=b), da/=db))
112 Warn("a /= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
115 if (failures > old_failures)
117 Error("%u failures on case %u da = %f, db = %f, a = %f, b = %f, aa = %f, bb = %f", failures-old_failures, i, da, db, Double(a), Double(b), Double(aa), Double(bb));
118 #if REAL == REAL_RATIONAL || REAL == REAL_RATIONAL_ARBINT
119 Debug("\tStrings are a = %s, b = %s, aa = %s, bb = %s", a.Str().c_str(), b.Str().c_str(), aa.Str().c_str(), bb.Str().c_str());
123 Debug("Completed %u test cases with total of %u operations, %u failures", TEST_CASES, 12*TEST_CASES, failures);
124 Debug("Total accumulated difference between Real and Double operations was %f", g_totalerror);