+/**
+ * Test mathematical operations on the Real type and consistency with double
+ */
+
#include "main.h"
#include "real.h"
static double g_totalerror = 0;
-bool NotEqual(double a, double b, double threshold=1e-1)
+bool NotEqual(double a, double b, double threshold=1e-4)
{
- double error = (fabs(a-b) > threshold);
+ double error = fabs(a-b);
g_totalerror += error;
return (error > threshold);
}
int main(int argc, char ** argv)
{
srand(time(NULL));
+ DebugRealInfo();
unsigned failures = 0;
for (unsigned i = 0; i < TEST_CASES; ++i)
{
- Debug("Test %u of %u", i, TEST_CASES);
+ //Debug("Test %u of %u", i, TEST_CASES);
double da = (double)(rand() + 1) / (double)(rand() + 1);
double db = (double)(rand() + 1) / (double)(rand() + 1);
{
failures++;
Warn("a /= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
+ }
+ if (NotEqual(Double(a*0.0 + 1.0), da*0.0 + 1.0))
+ {
+ failures++;
+ Warn("a * 0 = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
}
+
+ if (NotEqual(Double(a=b), da=db))
+ {
+ failures++;
+ Warn("a = b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
+ }
if (failures > old_failures)
{