Skip to main content
Log in

Mojo function

bit_ceil

bit_ceil(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.

Args:

  • val (Int): The input value.

Returns:

The smallest power of 2 that is greater than or equal to the input value.

bit_ceil[type: DType, width: Int, //](val: SIMD[type, width]) -> SIMD[$0, $1]

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.

Constraints:

The element type of the input vector must be integral.

Parameters:

  • type (DType): dtype used for the computation.
  • width (Int): SIMD width used for the computation.

Args:

  • val (SIMD[type, width]): The input value.

Returns:

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?