Backport log2 for the tree module