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?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?