remove a bad fix
[fw/sdcc] / support / regression / tests / muldiv.c
1 /** Simple test for the mul/div/mod operations.
2
3     type: int, signed char, short
4     storage: static,
5     attr: volatile,
6 */
7 #include <testfwk.h>
8
9 static void
10 testMul(void)
11 {
12     {attr} {storage} {type} i;
13     {type} result;
14
15     i = 5;
16
17     LOG(("i*5 == 25 = %u\n", (int)i*5));
18     result = i*5;
19     ASSERT(result == 25);
20     LOG(("i*-4 == -20 = %u\n", (int)i*-4));
21     ASSERT(i*-4 == -20);
22
23     i = -10;
24     LOG(("i*12 == -120 = %u\n", (int)i*12));
25     ASSERT(i*12 == -120);
26     LOG(("i*-3 == 30 = %u\n", (int)i*-3));
27     ASSERT(i*-3 == 30);
28
29     LOG(("30 == %u\n", (int)i*-3));
30 }
31
32 static void
33 testDiv(void)
34 {
35     {attr} {storage} {type} i;
36
37     i = 100;
38     LOG(("i/5 == 20 = %u\n", (int)i/5));
39     ASSERT(i/5 == 20);
40     LOG(("i/-4 == -25 = %u\n", (int)i/-4));
41     ASSERT(i/-4 == -25);
42
43     i = -50;
44     LOG(("i/25 == -2 = %u\n", (int)i/25));
45     ASSERT(i/25 == -2);
46     LOG(("i/-12 == 4 = %u\n", (int)i/-12));
47     ASSERT(i/-12 == 4);
48 }
49
50 static void
51 testMod(void)
52 {
53     {attr} {storage} {type} i;
54
55     // Disabled the LOG functions due to a bug in sdcc involving
56     // vaargs.
57     i = 100;
58     //    LOG(("i%%17 == 15 = %u\n", (int)(i%9)));
59     ASSERT(i%17 == 15);
60
61 #if MOD_SIGN_FOLLOWS_DIVIDEND
62     //    LOG(("i%%-7 == 2 = %u\n", (int)i%-7));
63     ASSERT(i%-7 == 2);
64
65     i = -49;
66     //    LOG(("i%%3 == -1 = %u\n", (int)i%3));
67     ASSERT(i%3 == -1);
68     //    LOG(("i%%-5 == -4 = %u\n", (int)i%-5));
69     ASSERT(i%-5 == -4);
70 #endif
71 }