X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=int64.c;h=8a1cda1a5fddc274816a133ba7aabf7ce1e0dba3;hb=49d2cf19accb059b3b68d1fc2b78e606a578c3e8;hp=da7b4c3b2ae0e28f669217bd8fb67f47cf63e40a;hpb=3730ada5ce457468441b32d7e84157e481b8ba75;p=PuTTY.git diff --git a/int64.c b/int64.c index da7b4c3b..8a1cda1a 100644 --- a/int64.c +++ b/int64.c @@ -5,10 +5,9 @@ */ #include +#include -typedef struct { - unsigned long hi, lo; -} uint64, int64; +#include "int64.h" uint64 uint64_div10(uint64 x, int *remainder) { @@ -37,11 +36,11 @@ void uint64_decimal(uint64 x, char *buffer) int start = 20; int d; - while (x.hi || x.lo) { + do { x = uint64_div10(x, &d); assert(start > 0); buf[--start] = d + '0'; - } + } while (x.hi || x.lo); memcpy(buffer, buf + start, sizeof(buf) - start); buffer[sizeof(buf) - start] = '\0'; @@ -69,3 +68,12 @@ uint64 uint64_add32(uint64 x, unsigned long y) yy.lo = y; return uint64_add(x, yy); } + +int uint64_compare(uint64 x, uint64 y) +{ + if (x.hi != y.hi) + return x.hi < y.hi ? -1 : +1; + if (x.lo != y.lo) + return x.lo < y.lo ? -1 : +1; + return 0; +}