Boost Users :
From: Daniel James (daniel_at_[hidden])
Date: 2005-08-22 13:30:07
Daniel Krügler wrote:
> To my opinion boost itself provides a simple helper class, namely
> static_log2, which allows the correct implementation by using the
> extended formular
> #include <boost/integer/static_log2.hpp>
> std::size_t const length
> = (std::numeric_limits<T>::digits *
> >::radix>::value +
> std::numeric_limits<int>::digits - 1)
> / std::numeric_limits<int>::digits;
> Note that the expression
> boost::static_log2<std::numeric_limits<T>::radix>::value is exactly 1
> in the usual base-2 case, but e.g. 4 in case of base-16.
> My proposed fix is exact in all cases, where radix is a power of 2, in
> other cases (like base-10) it would at least be a better approximation
> than the current one.
Thanks for letting me know, I need to think about this. It the radix
isn't a power of 2, then I guess that frexp and ldexp will be slow and
inaccurate. Maybe ldexp could be replaced with a multiplication.
As it is, I'm not happy with the current implementation. It might be
better to print the float to a string and then generate a hash value
from that. That's not great, but it might be more portable.
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