-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiint.c
41 lines (41 loc) · 895 Bytes
/
iint.c
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
typedef struct {
unsigned long *i;
unsigned int n;
} iint;
iint *iint_new (unsigned bound) {
long szl;
iint *egg;
if (!(egg = malloc (sizeof (iint))))
die ("RAM denied\n");
szl = sizeof (long);
egg->n = bound / szl + ((bound % szl) && 1);
if (!(egg->i = malloc (egg->n * szl)))
die ("RAM denied\n");
memset (egg->i, 0, egg->n * szl);
return egg;
}
int iint_add (iint * eye, unsigned long x) {
int ret = 0;
*(eye->i) += x;
if (*(eye->i) < x) {
if (--(eye->n)) {
eye->i++;
ret = iint_add (eye, 1L);
eye->i--;
}
else
ret = 1;
(eye->n)++;
}
return ret;
}
int iint_to_string (char *eye, iint * num) {
static char zp_lu[7];
unsigned i;
i = num->n;
sprintf (zp_lu, "%%0%lulx", 2 * sizeof (unsigned long));
while (i--)
eye += sprintf (eye, zp_lu, num->i[i]); /* woah! */
strcat (eye, "\n");
return 0;
}