Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-25 12:03:54


On Sat, 25 Jan 2003 15:06:54 +0200, "Vesa Karvonen"
<vesa_karvonen_at_[hidden]> wrote:

>Gennaro Prota:
>>Am I missing something?
>
>Yes. I have, in fact, previously explained how to use choose_n correctly.
>Please read more carefully. If something doesn't appear to make sense,
>reconsider your basic assumptions. Only after you have carefully
>reconsidered your assumptions, should you challenge the assertions of
>others.

Gulp! Sounds like a scold :-) Ok my fault. I admit that I should have
understood that the initial value was chosen as you say. In
retrospect, it's obvious that the choice as initial value of the n
such that

   2^n < MAX <= 2^ (2n) - 1

is the right way to go, since it ensures

   MAX / 2^n <= 2^n - 1/2^n < 2^n

and thus that at each step the part that "remains to be computed with
the subsequent steps" of the logarithm is at most n-1 (which can be
expressed as sum of n/2, n/4 ... 1)

> <excellent code snipped>

I'll do some benchmarks against the current implementation in
static_log2.hpp and post them here. I haven't tested your code yet but
now I'm convinced that it works :-) Thanks!

Genny.


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