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).
prev_power_of_two
prev_power_of_two(val: Int) -> Int
Computes the largest power of 2 that is less than or equal to the input value. Any integral value less than or equal to 0 will be floored to 0.
This operation is called bit_floor() in C++.
Args:
- val (
Int): The input value.
Returns:
Int: The largest power of 2 that is less than or equal to the input value.
prev_power_of_two[dtype: DType, width: Int, //](val: SIMD[dtype, width]) -> SIMD[dtype, width]
Computes the largest power of 2 that is less than or equal to the input value for each element of a SIMD vector. Any integral value less than or equal to 0 will be floored to 0.
This operation is called bit_floor() in C++.
Constraints:
The element type of the input vector must be integral.
Parameters:
Args:
- val (
SIMD[dtype, width]): The input value.
Returns:
SIMD[dtype, width]: A SIMD value where the element at position i is the largest power of 2
that is less than or equal to the integer at position i of the input
value.