ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
[boost] Re: A question about static_log2
by Gennaro Prota other posts by this author
Jan 23 2003 7:54PM messages near this date
Re: [boost] A question about static_log2 | math constant formal review request (was: [boost] Interval library merge)
On Thu, 23 Jan 2003 03:26:52 +0200, "Vesa Karvonen"
<vesa_karvonen@[...].com>  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.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Vesa Karvonen
Gennaro Prota

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved