Add an arbitrary base logarithm function and use it instead of C99-only log2().