wmbiff: added .gitignore.
[dockapps.git] / wmmon / ulllib.c
blob52efc3c4dafc805ac73ebd5325e19e5bb810762f
1 /*
2 * Unsigned long long arithmetic limited library, tailored for wmmon's
3 * specific needs.
5 * Copyright (c) 2014 Pedro Gimeno Fortea
7 * This file is part of wmmon.
9 * wmmon is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * wmmon is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with wmmon; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #ifndef HAVE_LONG_LONG_INT
26 #include "ulllib.h"
28 void ullreset(ullong *target) {
29 target->H = target->L = 0;
32 void ulladd(ullong *target, const ullong *toadd) {
33 unsigned long tmpL = toadd->L, tmpH = toadd->H;
34 target->L += tmpL;
36 /* Carry if the result is less than one of the operands */
37 target->H += tmpH + (target->L < tmpL);
40 long ullsub(const ullong *a, const ullong *b) {
41 /* Will wrap around correctly if necessary. Result is assumed to
42 fit a signed long. */
43 /* assert((a->H == b->H && a->L >= b->L)
44 || (a->H == b->H + 1 && a->L < b->L)); */
45 return a->L - b->L;
48 void ullparse(ullong *target, const char *str) {
49 ullong tmp;
51 ullreset(target);
52 while (*str >= '0' && *str <= '9') {
53 tmp = *target;
54 ulladd(target, target); /* *2 */
55 ulladd(target, target); /* *4 */
56 ulladd(target, &tmp); /* *5 */
57 ulladd(target, target); /* *10 */
58 tmp.H = 0;
59 tmp.L = *str - '0';
60 ulladd(target, &tmp); /* + digit */
61 ++str;
65 #endif /* HAVE_LONG_LONG_INT */
67 typedef int make_iso_compilers_happy;