On Fri, 24 Jan 2003 22:23:53 +0200, "Vesa Karvonen" <[EMAIL PROTECTED]> wrote:
>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. Maybe you are confusing the value, let's call it w, calculated by choose_n with the default value used for parameter n (which is w/2 or (w+1)/2)? If unsigned long has 48 value bits your choose_n template gives 32 but then you start with n = 16! This means you can, at most, calculate a logarithm = 31 (i.e. the log of 2**32 - 1). Am I missing something? Genny. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost