Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / support / regression / tcc / 118_switch.c
blob789dd06c757e46b67686ea81000dda79bd971351
1 #include <limits.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 int ibdg(long long n)
7 switch (n) {
8 case 1LL ... 9LL: return 1;
9 case 10LL ... 99LL: return 2;
10 case 100LL ... 999LL: return 3;
11 case 1000LL ... 9999LL: return 4;
12 case 10000LL ... 99999LL: return 5;
13 case 100000LL ... 999999LL: return 6;
14 case 1000000LL ... 9999999LL: return 7;
15 case 10000000LL ... 99999999LL: return 8;
16 case 100000000LL ... 999999999LL: return 9;
17 case 1000000000LL ... 9999999999LL: return 10;
18 case 10000000000LL ... 99999999999LL: return 11;
19 case 100000000000LL ... 999999999999LL: return 12;
20 case 1000000000000LL ... 9999999999999LL: return 13;
21 case 10000000000000LL ... 99999999999999LL: return 14;
22 case 100000000000000LL ... 999999999999999LL: return 15;
23 case 1000000000000000LL ... 9999999999999999LL: return 16;
24 case 10000000000000000LL ... 99999999999999999LL: return 17;
25 case 100000000000000000LL ... 999999999999999999LL: return 18;
26 case 1000000000000000000LL ... 9223372036854775807LL: return 19;
27 case -9223372036854775807LL-1LL ... -1LL: return 20;
29 return 0;
32 int ubdg(unsigned long long n)
34 switch (n) {
35 case 1ULL ... 9ULL: return 1;
36 case 10ULL ... 99ULL: return 2;
37 case 100ULL ... 999ULL: return 3;
38 case 1000ULL ... 9999ULL: return 4;
39 case 10000ULL ... 99999ULL: return 5;
40 case 100000ULL ... 999999ULL: return 6;
41 case 1000000ULL ... 9999999ULL: return 7;
42 case 10000000ULL ... 99999999ULL: return 8;
43 case 100000000ULL ... 999999999ULL: return 9;
44 case 1000000000ULL ... 9999999999ULL: return 10;
45 case 10000000000ULL ... 99999999999ULL: return 11;
46 case 100000000000ULL ... 999999999999ULL: return 12;
47 case 1000000000000ULL ... 9999999999999ULL: return 13;
48 case 10000000000000ULL ... 99999999999999ULL: return 14;
49 case 100000000000000ULL ... 999999999999999ULL: return 15;
50 case 1000000000000000ULL ... 9999999999999999ULL: return 16;
51 case 10000000000000000ULL ... 99999999999999999ULL: return 17;
52 case 100000000000000000ULL ... 999999999999999999ULL: return 18;
53 case 1000000000000000000ULL ... 9999999999999999999ULL: return 19;
54 case 10000000000000000000ULL ... 18446744073709551615ULL: return 20;
56 return 0;
59 int main(int argc, char **argv)
61 unsigned int i;
62 unsigned long long v = 1;
64 v = 1;
65 for (i = 1; i <= 20; i++) {
66 printf("%lld : %d\n", (long long) v, ibdg((long long)v));
67 v *= 10;
69 v = 1;
70 for (i = 1; i <= 20; i++) {
71 printf("%llu : %d\n", v, ubdg(v));
72 v *= 10;
74 return 0;