-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuint128.c
More file actions
46 lines (37 loc) · 864 Bytes
/
uint128.c
File metadata and controls
46 lines (37 loc) · 864 Bytes
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
#include <stdio.h>
#include <stdint.h>
typedef unsigned __int128 uint128;
void uint128_from_uint64(uint128* a, uint64_t* b) {
*a = (uint128)(*(uint64_t*)(b));
}
void uint128_to_uint64(uint128* a, uint64_t* b) {
*b = (uint64_t)(*(uint128*)(b));
}
void uint128_add(uint128* a, uint128* b, uint128* c) {
*c = *a + *b;
}
void uint128_sub(uint128* a, uint128* b, uint128* c) {
*c = *a - *b;
}
// void uint128_abs(uint128* a, uint128* b) {
// if (*a > 0) {
// *b = *a;
// } else {
// *b = -*a;
// }
// }
void uint128_mul(uint128* a, uint128* b, uint128* c) {
*c = *a * *b;
}
void uint128_div(uint128* a, uint128* b, uint128* c) {
*c = *a / *b;
}
int uint128_cmp(uint128* a, uint128* b) {
if (*a > *b) {
return 1;
} else if (*a < *b) {
return -1;
} else {
return 0;
}
}