Doubling-loop ceiling logarithm
ID: doubling-loop-ceiling-logarithm
For positive , start at and repeatedly increment and double while . In exact integer arithmetic, the loop invariant together with or yields at exit. For fixed-width arithmetic, this proof requires every useful doubling to be representable. A signed 32-bit doubling variable becomes negative at and then zero, so the loop need not terminate for inputs above . Widening the variable to a signed 64-bit type repairs the algorithm for positive 32-bit inputs.
New to topics? Read the docs here!