about summary refs log tree commit diff homepage
path: root/test/Concrete/_testingUtils.c
blob: 02d0529e0d91b60d3cf085719317b3046acc05f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int putchar(int x);

void print_int(unsigned long long val);

#define TYPED_PRINT(_name_type, _arg_type)  \
    void print_ ## _name_type(_arg_type val) { print_int(val); }
 
TYPED_PRINT(i1, unsigned char)
TYPED_PRINT(i8, unsigned char)
TYPED_PRINT(i16, unsigned short)
TYPED_PRINT(i32, unsigned int)
TYPED_PRINT(i64, unsigned long long)

void print_int(unsigned long long val) {
    int cur = 1;

    // effectively do a log (can't call log because it returns floats)
    // do the nasty divide to prevent overflow
    while (cur <= val / 10)
        cur *= 10;

    while (cur) {
        int digit = val / cur;

        putchar(digit + '0');
        
        val = val % cur;
        cur /= 10;
    }
    
    putchar('\n');
}