log2(): Base-2 Logarithm
log2() returns the exponent of 2 that produces a positive input. It is useful for binary data sizes, algorithmic complexity, tree depth, and repeated halving.
Binary interpretation
log2(8) is 3 because 2³ is 8. Real inputs must be positive; zero and negative values have no real logarithm. Reverse a result using pow(), and use log() when a natural-log formula is required.
In data structures, a base-2 logarithm often describes how many balanced decisions are needed to search a range. Use floor() or ceil() only after deciding whether partial levels should count.