IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b1
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

log2_floor

log2_floor(val: Int) -> Int

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

Args:

  • val (Int): The input value.

Returns:

Int: The floor of the base-2 logarithm of the input value, which is equal to the position of the highest set bit. Returns -1 if val is 0 or negative.

log2_floor[dtype: DType, width: Int, //](val: SIMD[dtype, width]) -> SIMD[dtype, width]

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

Parameters:

  • dtype (DType): The dtype of the input SIMD vector.
  • width (Int): The width of the input and output SIMD vector.

Args:

Returns:

SIMD[dtype, width]: The floor of the base-2 logarithm of the input value, which is equal to the position of the highest set bit. Returns -1 if val is 0 or negative.