3 operation: ADD, SUB, MUL, DIV, REVDIV
7 // we are in the regression tests
25 # define STORAGE __xdata
26 # define XDATA __xdata
28 # define STORAGE __code
35 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
36 XDATA
volatile float left
, right
, result
;
39 float left
, right
, add
, sub
, mul
, div
, revdiv
;
41 // left right add sub mul div revdiv
42 { 12.8, 25.6, 38.4, -12.8, 327.68, 0.5, 2},
43 { 12.8, -25.6, -12.8, 38.4, -327.68, -0.5, -2},
44 { -12.8, 25.6, 12.8, -38.4, -327.68, -0.5, -2},
45 { -12.8, -25.6, -38.4, 12.8, 327.68, 0.5, 2},
46 { 100.0, 10.0, 110.0, 90.0, 1000.00, 10.0, 0.1},
47 { 1000.0, 10.0, 1010.0, 990.0, 10000.00, 100.0, 0.01},
48 { 10000.0, 10.0, 10010.0, 9990.0, 100000.00, 1000.0, 0.001},
49 { 100000.0, 10.0, 100010.0, 99990.0, 1000000.00, 10000.0, 0.0001},
50 { 1000000.0, 10.0, 1000010.0, 999990.0, 10000000.00, 100000.0, 0.00001},
51 {10000000.0, 10.0,10000010.0, 9999990.0,100000000.00, 1000000.0, 0.000001},
52 { 0x100, 0x10, 0x110, 0xf0, 0x1000, 0x10, 0.0625},
53 { 0x1000, 0x10, 0x1010, 0xff0, 0x10000, 0x100, 0.00390625},
54 { 0x10000, 0x10, 0x10010, 0xfff0, 0x100000, 0x1000, 0.00024414},
55 { 0x100000, 0x10, 0x100010, 0xffff0, 0x1000000, 0x10000, 0 /* ignore */},
56 { 0x1000000, 0x10, 0x1000010, 0xfffff0, 0x10000000, 0x100000, 0 /* ignore */},
57 {0x10000000, 0x10,0x10000010, 0xffffff0, (float)0x10000000*0x10,
58 0x1000000, 0 /* ignore */},
61 XDATA
int tests
= 0, errors
= 0;
64 compare (float is
, float should
)
66 float diff
= should
? is
/ should
: 0;
68 DEBUG (printf (" %1.3f (%f %f) ", is
, should
, diff
));
72 DEBUG (printf ("IGNORED!\n"));
76 // skip the fp roundoff errors
77 if (diff
> 0.999999 && diff
< 1.00001)
79 DEBUG (printf ("OK!\n"));
86 DEBUG (printf ("FAIL!\n"));
96 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
98 int t
= sizeof (cases
) / sizeof (cases
[0]);
101 for (i
= 0; i
< t
; i
++)
103 DEBUG (printf ("Case %d ", i
));
106 result
= cases
[i
].left
+ cases
[i
].right
;
107 DEBUG (printf ("%1.3f + %1.3f =", cases
[i
].left
, cases
[i
].right
));
108 compare (result
, cases
[i
].add
);
112 result
= cases
[i
].left
- cases
[i
].right
;
113 DEBUG (printf ("%1.3f - %1.3f =", cases
[i
].left
, cases
[i
].right
));
114 compare (result
, cases
[i
].sub
);
118 result
= cases
[i
].left
* cases
[i
].right
;
119 DEBUG (printf ("%1.3f * %1.3f =", cases
[i
].left
, cases
[i
].right
));
120 compare (result
, cases
[i
].mul
);
124 result
= cases
[i
].left
/ cases
[i
].right
;
125 DEBUG (printf ("%1.3f / %1.3f =", cases
[i
].left
, cases
[i
].right
));
126 compare (result
, cases
[i
].div
);
130 result
= cases
[i
].right
/ cases
[i
].left
;
131 DEBUG (printf ("%1.3f / %1.3f =", cases
[i
].right
, cases
[i
].left
));
132 compare(result
, cases
[i
].revdiv
);
135 DEBUG (printf ("%d tests, %d errors\n", tests
, errors
));
140 testFloatMulRound (void)
142 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
144 result
= 10.61 * right
;
145 compare (result
, 2.0);
154 testFloatMulRound ();