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: Nightly
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).

pow

def pow(base: SIMD, exp: SIMD) -> SIMD[base.dtype, base.length]

Computes the base raised elementwise to the power of the exp.

For an integral base, a negative exponent aborts.

Constraints:

The exp must have the same dtype and width as the base, or be a scalar. An integral base requires an integral exp.

Args:

  • ​base (SIMD): The base of the power operation.
  • ​exp (SIMD): The exponent of the power operation.

Returns:

SIMD[base.dtype, base.length]: The base raised elementwise to the power of the exp.

def pow(base: SIMD, exp: FloatLiteral) -> SIMD[base.dtype, base.length]

Computes the base raised elementwise to the power of a float literal.

Constraints:

The base must be floating point.

Args:

  • ​base (SIMD): The base of the power operation.
  • ​exp (FloatLiteral): The exponent, converted to the dtype of base.

Returns:

SIMD[base.dtype, base.length]: The base raised elementwise to the power of the exp.

def pow[dtype: DType, width: SIMDLength, //](base: SIMD[dtype, width], exp: SIMD[dtype, width], mod: SIMD[dtype, width]) -> SIMD[dtype, width] where dtype.is_integral()

Computes base raised to the power of exp, modulo mod, elementwise.

For example, pow(3, 4, 5) is 1, pow(2, 3, -5) is -2, and pow(3, -1, 7) is 5, because 3 * 5 % 7 == 1.

Constraints:

The dtype must be an integral type of at most 64 bits.

Parameters:

  • ​dtype (DType): The dtype of the inputs and the result.
  • ​width (SIMDLength): The width of the inputs and the result.

Args:

Returns:

SIMD[dtype, width]: The base raised to the power of exp, modulo mod. Aborts if mod is zero, or if exp is negative and base has no inverse modulo mod.