OxL Reference

method usize.clamp

lo when the value is below it, hi when it is above, the value itself otherwise.

Example:

oxl✓ checked in CI
fn main() io {
  let a: usize = 15
  print("{a.clamp(0, 10)} {(5 as usize).clamp(0, 10)}")
}
Output
10 5
pub(api) fn clamp(lo: usize, hi: usize) -> usize

Complexity. O(1).

Since. 1.0.0-beta

Parameters

NameType
lousize
hiusize

Returns

usize

Effects

none declared (pure unless the body says otherwise)

Defined in: std/core/numbers.oxl:3569

See also