Boost logo

Boost Users :

Subject: Re: [Boost-users] About naming of integer log in base 2
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2010-07-21 12:42:32


 

 

From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Murilo Adriano
Vasconcelos
Sent: Tuesday, July 20, 2010 3:39 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] About naming of integer log in base 2

 

Hi,

 

 

Maybe, it depends on the relative cost of two: the reason for unchecked_factorial is that low-order factorials are often
used inside the inner loop of a computation, where anything more expensive than a simple table lookup is out of the
question (and the check can easily be moved outside the loop anyway). Does the same thing apply here.... or is the cost
of the check trivial compared to the bit manipulations? I don't know the answers to these BTW, just some questions you
might want to think about ;-)

 

Thank you John!

 

I thought better and followed Paul's recommendations and implemented math::policies on ilog2() [0], and also changed the
count_leading_zeros(T value) to return the size in bits of T when value is equal to 0 (all bits are leading 0's).

 

So I've added two ifs, but think that the design of the functions are better.

 

[0] - https://svn.boost.org/trac/boost/browser/sandbox/SOC/2010/bits_and_ints/boost/integer/ilog2.hpp?rev=64198

 

Looks more promising, but you have a typo in the error message ;-)

 

retunrning -1",

 

and maybe you need to document some examples of using policies that don't bother to check or at least do so quietly
(your original idea), just quietly return -1, produce a message and return -1, or message and then throw an exception?

 

But maybe it's a TODO ;-)

 

Paul

 

---
Paul A. Bristow
Prizet Farmhouse
Kendal, UK   LA8 8AB
+44 1539 561830, mobile +44 7714330204
pbristow_at_[hidden]
 
 
 
 
 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net