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

scalb

def scalb[dtype: DType, width: SIMDLength, //](arg0: SIMD[dtype, width], arg1: SIMD[dtype, width]) -> SIMD[dtype, width] where dtype.is_floating_point()

Scales each value in arg0 by 2 raised to its exponent in arg1.

A finite, non-integral exponent produces NaN. A positive infinite exponent produces infinity with the sign of arg0, except that a zero base produces NaN. A negative infinite exponent produces zero with the sign of arg0, except that an infinite base produces NaN. NaN arguments produce NaN.

For example:

from std.math import scalb
var scaled = scalb(Float32(1.5), Float32(2.0))

Constraints:

The input must be a floating-point type. The float64 type is not supported on Apple GPU.

Parameters:

  • ​dtype (DType): The dtype of the input and output SIMD vector.
  • ​width (SIMDLength): The width of the input and output SIMD vector.

Args:

Returns:

SIMD[dtype, width]: The scaled values, computed elementwise.