2 * Unsigned long long arithmetic limited library, tailored for wmmon's
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
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
;
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
43 /* assert((a->H == b->H && a->L >= b->L)
44 || (a->H == b->H + 1 && a->L < b->L)); */
48 void ullparse(ullong
*target
, const char *str
) {
52 while (*str
>= '0' && *str
<= '9') {
54 ulladd(target
, target
); /* *2 */
55 ulladd(target
, target
); /* *4 */
56 ulladd(target
, &tmp
); /* *5 */
57 ulladd(target
, target
); /* *10 */
60 ulladd(target
, &tmp
); /* + digit */
65 #endif /* HAVE_LONG_LONG_INT */
67 typedef int make_iso_compilers_happy
;