BartC <[email protected]>:
> On 08/04/2015 23:06, Marko Rauhamaa wrote:
>> Arithmetics is performed just like in elementary school.
>
> Not in the school I went to; we used decimal!
The basic arithmetic algorithms are independent of the base.
For example, here's how you can add two 128-bit integers in C using
64-bit digits:
typedef struct {
uint64_t lo, hi;
} uint128_t;
uint128_t add128(uint128_t x, uint128_t y)
{
uint128_t result = {
.lo = x.lo + y.lo,
.hi = x.hi + y.hi
};
if (result.lo < x.lo)
result.hi++;
return result;
}
Works both for signed and unsigned integers.
Marko
--
https://mail.python.org/mailman/listinfo/python-list