-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathcarp_long.h
103 lines (96 loc) · 2.03 KB
/
carp_long.h
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Long Long__PLUS_(Long x, Long y) {
return x + y;
}
Long Long__MINUS_(Long x, Long y) {
return x - y;
}
Long Long__MUL_(Long x, Long y) {
return x * y;
}
Long Long__DIV_(Long x, Long y) {
return x / y;
}
#if defined __GNUC__
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
return __builtin_add_overflow(x, y, res);
}
bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
return __builtin_sub_overflow(x, y, res);
}
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
return __builtin_mul_overflow(x, y, res);
}
#else
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
Long r = x + y;
*res = r;
return (y > 0) && (x > (INT64_MAX - y)) || (y < 0) && (x < (INT64_MIN - y));
}
bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
Long r = x - y;
*res = r;
return (y > 0 && x < (INT64_MIN + y)) || (y < 0 && x > (INT64_MAX + y));
}
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
Long r = x * y;
*res = r;
return y == 0 || (r / y) != x;
}
#endif
bool Long__EQ_(Long x, Long y) {
return x == y;
}
bool Long__LT_(Long x, Long y) {
return x < y;
}
bool Long__GT_(Long x, Long y) {
return x > y;
}
Long Long_neg(Long x) {
return -x;
}
Long Long_inc(Long x) {
return x + 1;
}
Long Long_dec(Long x) {
return x - 1;
}
Long Long_abs(Long x) {
return x > 0 ? x : -x;
}
Long Long_bit_MINUS_shift_MINUS_left(Long x, Long y) {
return x << y;
}
Long Long_bit_MINUS_shift_MINUS_right(Long x, Long y) {
return x >> y;
}
Long Long_bit_MINUS_and(Long x, Long y) {
return x & y;
}
Long Long_bit_MINUS_or(Long x, Long y) {
return x | y;
}
Long Long_bit_MINUS_xor(Long x, Long y) {
return x ^ y;
}
Long Long_bit_MINUS_not(Long x) {
return ~x;
}
Long Long_copy(const Long* x) {
return *x;
}
Long Long_mod(Long x, Long divider) {
return x % divider;
}
void Long_seed(Long seed) {
srand(seed);
}
bool Long_mask(Long a, Long b) {
return a & b;
}
int Long_to_MINUS_int(Long a) {
return (int)a;
}
Long Long_from_MINUS_int(int a) {
return (Long)a;
}