Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-23 14:54:05


On Thu, 23 Jan 2003 03:26:52 +0200, "Vesa Karvonen"
<vesa_karvonen_at_[hidden]> wrote:

>Hi,
>
>I'm sorry, but I have too little time to comment more extensively on this
>subject

No problem. I just have to thank you for the attention and the useful
comments. Feel also free to continue the discussion when you'll have
more time even if this thread is then "old", and/or to contact me by
private mail.

> (other duties demand attention). Below you'll find an algorithm,
>that chooses a proper value of n from where to start the log2<> algorithm
>presented earlier.

Before resorting to the = sizeof hack I thought to several solutions.
It's obvious that the value we need is just 1 + log2<ULONG_MAX>. So
one solution would have been to use the trivial log2 = 1+log2(n/2)
implementation for the initial value only, and the optimized binary
search implementation for the rest. Since unsigned long are guaranteed
to have at least 32 value bits, one could have done:

 const int initial_value = 31 + trivial_log2 (ULONG_MAX/2147483648ul)

saving some thirty instantiations. Still it would give you an error
with 64 bits ulongs and compilers with a small instantiation limit
however, thus I gave up.

> It does not depend on <limits> and it should always
>produce a value that has the correct properties.

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? I'll think about the issue
and see if I have anything better than this. If so I'll post it here.

Genny.


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