Best search algorithm to find condition within a range
Alain Ketterlin
alain at dpt-info.u-strasbg.fr
Thu Apr 9 07:57:48 EDT 2015
Marko Rauhamaa <marko at pacujo.net> writes:
> The basic arithmetic algorithms are independent of the base.
Right.
> 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.
(Slightly off-topic, but...)
No, it would not work for signed integers (i.e., with lo and hi of
int64_t type), because overflow is undefined behavior for signed.
-- Alain.
More information about the Python-list
mailing list