7 #define TEST_CASES 1000
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 //Debug("Test %u of %u", i, TEST_CASES);
26 double da = (double)(rand() + 1) / (double)(rand() + 1);
27 double db = (double)(rand() + 1) / (double)(rand() + 1);
38 unsigned old_failures = failures;
39 if (NotEqual(Double(a), Double(aa)))
42 Warn("a != Real(a); %f vs %f", Double(a), Double(aa));
44 if (NotEqual(Double(b), Double(bb)))
47 Warn("b != Real(b); %f vs %f", Double(b), Double(bb));
50 if (NotEqual(Double(a), da))
53 Warn("a != da; %f vs %f", Double(a), da);
55 if (NotEqual(Double(b), db))
58 Warn("b != db; %f vs %f", Double(b), db);
60 if (NotEqual(Double(a+b), da+db))
63 Warn("a + b = %f should be %f", Double(a+b), da+db);
65 if (NotEqual(Double(a-b), da-db))
68 Warn("a - b = %f should be %f", Double(a-b), da-db);
70 if (NotEqual(Double(a*b), da*db))
73 Warn("a * b = %f should be %f", Double(a*b), da*db);
75 if (NotEqual(Double(a/b), da/db))
78 Warn("a / b = %f should be %f", Double(a/b), da/db);
81 if (NotEqual(Double(a), da))
84 Warn("a has changed after +-*/ from %f to %f", da, Double(a));
86 if (NotEqual(Double(b), db))
89 Warn("b has changed after +-*/ from %f to %f", db, Double(b));
92 if (NotEqual(Double(a+=b), da+=db))
95 Warn("a += b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
98 if (NotEqual(Double(a-=b), da-=db))
101 Warn("a -= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
104 if (NotEqual(Double(a*=b), da*=db))
107 Warn("a *= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
110 if (NotEqual(Double(a/=b), da/=db))
113 Warn("a /= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
116 if (failures > old_failures)
118 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));
119 #if REAL == REAL_RATIONAL || REAL == REAL_RATIONAL_ARBINT
120 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());
124 Debug("Completed %u test cases with total of %u operations, %u failures", TEST_CASES, 12*TEST_CASES, failures);
125 Debug("Total accumulated difference between Real and Double operations was %f", g_totalerror);