Skip to main content

Mojo function

log2_ceil

log2_ceil(val: Int) -> Int

Returns the ceiling of the base-2 logarithm of an integer value.

Args:

  • val (Int): The input value.

Returns:

The ceiling of the base-2 logarithm of the input value, which corresponds to the smallest power of 2 greater than or equal to the input. Returns 0 if val is 0.

log2_ceil(val: SIMD[dtype, 1]) -> SIMD[dtype, 1]

Returns the ceiling of the base-2 logarithm of an integer value.

Args:

  • val (SIMD[dtype, 1]): The input value.

Returns:

The smallest integer n such that 2^n is greater than or equal to the input value. Returns 0 if val is 0.

Was this page helpful?