Mojo function
next_power_of_two
next_power_of_two(val: Int) -> Int
Computes the smallest power of 2 that is greater than or equal to the input value. Any integral value less than or equal to 1 will be ceiled to 1.
Notes:
This operation is called bit_ceil() in C++.
Args:
- val (
Int): The input value.
Returns:
Int: The smallest power of 2 that is greater than or equal to the input
value.
next_power_of_two(val: UInt) -> UInt
Computes the smallest power of 2 that is greater than or equal to the input value. Any integral value less than or equal to 1 will be ceiled to 1.
Notes:
This operation is called bit_ceil() in C++.
Args:
- val (
UInt): The input value.
Returns:
UInt: The smallest power of 2 that is greater than or equal to the input
value.
next_power_of_two[dtype: DType, width: Int, //](val: SIMD[dtype, width]) -> SIMD[dtype, width]
Computes the smallest power of 2 that is greater than or equal to the input value for each element of a SIMD vector. Any integral value less than or equal to 1 will be ceiled to 1.
This operation is called bit_ceil() in C++.
Constraints:
The element type of the input vector must be integral.
Parameters:
Args:
- val (
SIMD): The input value.
Returns:
SIMD: A SIMD value where the element at position i is the smallest power of 2
that is greater than or equal to the integer at position i of the input
value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!