else
{
Debug("Add random object");
- doc.Add(RECT_FILLED, Rect(Random()*0.5, Random()*0.5, Random()*0.5, Random()*0.5));
+ //doc.Add(RECT_FILLED, Rect(Random()*0.5, Random()*0.5, Random()*0.5, Random()*0.5));
+ doc.Add(RECT_FILLED, Rect(0.25,0.25, 0.5, 0.5));
}
MainLoop(doc);
return 0;
{
//#define REAL_FLOAT
-#define REAL_DOUBLE
-//#define REAL_HALF
+//#define REAL_DOUBLE
+#define REAL_HALF
#ifdef REAL_SINGLE
typedef float Real;
// mask out extra bits in exponent
//1000 1111 1000 0000 0000 0011 1111 1111
// Endianness matters
- a &= 0xFF3008F8;//0x8F8003FF;
+ a &= 0xFFC001F1; //0x8F8003FF;
}
#include "main.h"
-float test = 1e4;
+#include <cmath>
+float test_min = 0;
+float test_max = 1e-6;
+unsigned test_count = 100;
+float error_thresh = (test_max - test_min)/1e1;
int main(int argc, char ** argv)
{
- Real r(test);
- Debug("test float %.20f", test);
- Debug("test real %.20f", Float(r));
+ Debug("TEST STARTING - Comparing Float(Real(test)) for %u trials between %.20f and %.20f", test_count, test_min, test_max);
+ float error;
+ for (unsigned i = 0; i < test_count; ++i)
+ {
+ float test = test_min + (test_max-test_min)*((float)(rand() % (int)1e6)/1e6);
+ Real real(test);
+ float thiserror = abs(test - real.value);
+ error += thiserror;
+ Debug("#%u: |test %.20f - real %.20f| = %.20f [mean %f]", i, test, real.value, thiserror, error/(i+1));
+ }
+
+ if (error/test_count > error_thresh)
+ {
+ Fatal("TEST FAILED - Average error %.20f exceeds threshold %.20f", error/test_count, error_thresh);
+ }
+ Debug("TEST SUCCEEDED - Average error %.20f is %f percent of range", error/test_count, 1e2*(error/test_count) / (test_max - test_min));
return 0;
}