Boost logo

Boost :

From: Vesa Karvonen (vesa_karvonen_at_[hidden])
Date: 2003-01-24 15:23:53


Gennaro Prota:
>Vesa Karvonen:
>>Gennaro Prota:
>>>Vesa, I really appreciate your attempt but your code assumes the
>>>required number to be a power of two (it just tries 32, 64, 128,
>>>etc.). What about 48 bits unsigned long?[...]
>>
>>If unsigned long has 48 bits, then an n of 32 would be chosen.
>
>And then you are not able to calculate log2 for numbers in the range
>[2**32, 2**48-1[ (at least).

The algorithm calculates log2 correctly even for those numbers. The
invariant of the core algorithm is that at the start of each recursion 1 <=
x && x>>n < 1ul<<n.

Regards,
  Vesa Karvonen

_________________________________________________________________


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk