mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
Some extra int64 functions.
[originally from svn r6778]
This commit is contained in:
parent
9ca35dd9e5
commit
3d522cfd08
51
int64.c
51
int64.c
@ -77,3 +77,54 @@ int uint64_compare(uint64 x, uint64 y)
|
|||||||
return x.lo < y.lo ? -1 : +1;
|
return x.lo < y.lo ? -1 : +1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64 uint64_subtract(uint64 x, uint64 y)
|
||||||
|
{
|
||||||
|
x.lo -= y.lo;
|
||||||
|
x.hi -= y.hi + (x.lo > ~y.lo ? 1 : 0);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
double uint64_to_double(uint64 x)
|
||||||
|
{
|
||||||
|
return (4294967296.0 * x.hi) + (double)x.lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 uint64_shift_right(uint64 x, int shift)
|
||||||
|
{
|
||||||
|
if (shift < 32) {
|
||||||
|
x.lo >>= shift;
|
||||||
|
x.lo |= (x.hi << (32-shift));
|
||||||
|
x.hi >>= shift;
|
||||||
|
} else {
|
||||||
|
x.lo = x.hi >> (shift-32);
|
||||||
|
x.hi = 0;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 uint64_shift_left(uint64 x, int shift)
|
||||||
|
{
|
||||||
|
if (shift < 32) {
|
||||||
|
x.hi <<= shift;
|
||||||
|
x.hi |= (x.lo >> (32-shift));
|
||||||
|
x.lo <<= shift;
|
||||||
|
} else {
|
||||||
|
x.hi = x.lo << (shift-32);
|
||||||
|
x.lo = 0;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 uint64_from_decimal(char *str)
|
||||||
|
{
|
||||||
|
uint64 ret;
|
||||||
|
ret.hi = ret.lo = 0;
|
||||||
|
while (*str >= '0' && *str <= '9') {
|
||||||
|
ret = uint64_add(uint64_shift_left(ret, 3),
|
||||||
|
uint64_shift_left(ret, 1));
|
||||||
|
ret = uint64_add32(ret, *str - '0');
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
5
int64.h
5
int64.h
@ -15,5 +15,10 @@ uint64 uint64_make(unsigned long hi, unsigned long lo);
|
|||||||
uint64 uint64_add(uint64 x, uint64 y);
|
uint64 uint64_add(uint64 x, uint64 y);
|
||||||
uint64 uint64_add32(uint64 x, unsigned long y);
|
uint64 uint64_add32(uint64 x, unsigned long y);
|
||||||
int uint64_compare(uint64 x, uint64 y);
|
int uint64_compare(uint64 x, uint64 y);
|
||||||
|
uint64 uint64_subtract(uint64 x, uint64 y);
|
||||||
|
double uint64_to_double(uint64 x);
|
||||||
|
uint64 uint64_shift_right(uint64 x, int shift);
|
||||||
|
uint64 uint64_shift_left(uint64 x, int shift);
|
||||||
|
uint64 uint64_from_decimal(char *str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user