Skip to main content
Log in

Mojo function

is_power_of_two

is_power_of_two(val: Int) -> Bool

Checks if the input value is a power of 2.

Args:

  • val (Int): The input value.

Returns:

True if the input value is a power of 2, False otherwise.

is_power_of_two[type: DType, width: Int, //](val: SIMD[type, width]) -> SIMD[bool, width]

Checks if the input value is a power of 2 for each element of a SIMD vector.

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 True if the integer at position i of the input value is a power of 2, False otherwise.