X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=support%2Fregression%2Ftests%2Ffloat.c;h=e2585aa3fad42a97150d36b4fa818fa15f88ad01;hb=7fb0107529064728ffc2ece8df9f87825533e83b;hp=2a4211444b0960ff2097bd9777f39cd540cc657c;hpb=07df12abd9fe9f3ff2fa7edb177ff5e38a78324c;p=fw%2Fsdcc diff --git a/support/regression/tests/float.c b/support/regression/tests/float.c index 2a421144..e2585aa3 100644 --- a/support/regression/tests/float.c +++ b/support/regression/tests/float.c @@ -1,25 +1,131 @@ -/* Simple floating pt tests. - */ -#include +/* Float tests. -void -testFloatAdd(void) -{ - volatile float result, left, right; + operation: ADD, SUB, MUL, DIV, REVDIV +*/ + +#if 1 + // we are in the regression tests + #include + #define DEBUG(x) + + #define {operation} 1 +#else + // we are standalone + #include + #define DEBUG(x) x + #define ASSERT(x) + #define ADD 1 + #define SUB 1 + #define MUL 1 + #define DIV 1 + #define REVDIV 1 +#endif + +#ifdef SDCC_mcs51 +# define STORAGE xdata +# define XDATA xdata +#elif SDCC_pic16 +# define STORAGE code +# define XDATA +#else +# define STORAGE +# define XDATA +#endif + +XDATA volatile float left, right, result; + +struct { + float left, right, add, sub, mul, div, revdiv; +} STORAGE cases[]={ + // left right add sub mul div revdiv + { 12.8, 25.6, 38.4, -12.8, 327.68, 0.5, 2}, + { 12.8, -25.6, -12.8, 38.4, -327.68, -0.5, -2}, + { -12.8, 25.6, 12.8, -38.4, -327.68, -0.5, -2}, + { -12.8, -25.6, -38.4, 12.8, 327.68, 0.5, 2}, + { 100.0, 10.0, 110.0, 90.0, 1000.00, 10.0, 0.1}, + { 1000.0, 10.0, 1010.0, 990.0, 10000.00, 100.0, 0.01}, + { 10000.0, 10.0, 10010.0, 9990.0, 100000.00, 1000.0, 0.001}, + { 100000.0, 10.0, 100010.0, 99990.0, 1000000.00, 10000.0, 0.0001}, + { 1000000.0, 10.0, 1000010.0, 999990.0, 10000000.00, 100000.0, 0.00001}, + {10000000.0, 10.0,10000010.0, 9999990.0,100000000.00, 1000000.0, 0.000001}, + { 0x100, 0x10, 0x110, 0xf0, 0x1000, 0x10, 0.0625}, + { 0x1000, 0x10, 0x1010, 0xff0, 0x10000, 0x100, 0.00390625}, + { 0x10000, 0x10, 0x10010, 0xfff0, 0x100000, 0x1000, 0.00024414}, + { 0x100000, 0x10, 0x100010, 0xffff0, 0x1000000, 0x10000, 0 /* ignore */}, + { 0x1000000, 0x10, 0x1000010, 0xfffff0, 0x10000000, 0x100000, 0 /* ignore */}, + {0x10000000, 0x10,0x10000010, 0xffffff0, (float)0x10000000*0x10, + 0x1000000, 0 /* ignore */}, +}; - left = 4; - right = 5; - ASSERT(left+right == 9); +XDATA int tests=0, errors=0; - left = 7; - right = -3; - ASSERT(left+right == 4); +char compare (float is, float should) { + float diff = should ? is/should : 0; + tests++; + DEBUG(printf (" %1.3f (%f %f) ", is, should, diff)); - left = -1234; - right = 409; - ASSERT(left+right == (-1234+409)); + if (should==0) { + DEBUG(printf ("IGNORED!\n")); + return 0; + } + + // skip the fp roundoff errors + if (diff>0.999999 && diff<1.00001) { + DEBUG(printf ("OK!\n")); + ASSERT(1); + return 0; + } else { + errors++; + DEBUG(printf ("FAIL!\n")); + ASSERT(0); + return 1; + } +} + +void +testFloatMath(void) +{ + int i; + int t = sizeof(cases)/sizeof(cases[0]); + float result; + + for (i=0; i