STXXL provides three methods to calculate log2(x), which is often needed for binary trees, etc.
The first is during compile-time using template meta-programming magic:
#include <stxxl/bits/common/tmeta.h>
std::cout << stxxl::LOG2<10000>::floor << std::endl;
std::cout << stxxl::LOG2<10000>::ceil << std::endl;
The second is for calculating log2(x) for integer arguments using simple bit shift arithmetic:
#include <stxxl/bits/common/utils.h>
std::cout << stxxl::ilog2_floor(10000) << std::endl;
std::cout << stxxl::ilog2_ceil(10000) << std::endl;
The third and probably least useful is to use conversion to double and math.h's
facilities:
#include <stxxl/bits/common/utils.h>
std::cout << stxxl::log2_floor(10000) << std::endl;
std::cout << stxxl::log2_ceil(10000) << std::endl;