Skip to main content
Log in

Mojo function

clamp

clamp(val: Int, lower_bound: Int, upper_bound: Int) -> Int

Clamps the integer value vector to be in a certain range.

Args:

  • ​val (Int): The value to clamp.
  • ​lower_bound (Int): Minimum of the range to clamp to.
  • ​upper_bound (Int): Maximum of the range to clamp to.

Returns:

An integer clamped to be within lower_bound and upper_bound.

clamp(val: UInt, lower_bound: UInt, upper_bound: UInt) -> UInt

Clamps the integer value vector to be in a certain range.

Args:

  • ​val (UInt): The value to clamp.
  • ​lower_bound (UInt): Minimum of the range to clamp to.
  • ​upper_bound (UInt): Maximum of the range to clamp to.

Returns:

An integer clamped to be within lower_bound and upper_bound.

clamp(val: SIMD[type, size], lower_bound: SIMD[type, size], upper_bound: SIMD[type, size]) -> SIMD[$0, $1]

Clamps the values in a SIMD vector to be in a certain range.

Clamp cuts values in the input SIMD vector off at the upper bound and lower bound values. For example, SIMD vector [0, 1, 2, 3] clamped to a lower bound of 1 and an upper bound of 2 would return [1, 1, 2, 2].

Args:

  • ​val (SIMD[type, size]): The value to clamp.
  • ​lower_bound (SIMD[type, size]): Minimum of the range to clamp to.
  • ​upper_bound (SIMD[type, size]): Maximum of the range to clamp to.

Returns:

A SIMD vector containing x clamped to be within lower_bound and upper_bound.

Was this page helpful?