Function in num coil-stdlib

clamp

fn clamp<T: Ord>(T x, T lo, T hi) -> T
Import
use num::{clamp};
Source: src/num.hy

Returns x limited to the range lo..=hi.

Parameters#

NameType
xT
loT
hiT

Returns#

T

Examples#

use num::{clamp};
use tests::assert;
assert!(clamp(15, 0, 10) == 10);
assert!(clamp(-3, 0, 10) == 0);
assert!(clamp(4, 0, 10) == 4);

See also#

  • abs: Returns the absolute value of x.
  • min: Returns the smaller of a and b (a when they are equal).
  • max: Returns the larger of a and b (a when they are equal).
  • round: Rounds x to the nearest whole number; halves round away from zero.
  • signum: Returns -1, 0 or 1 by the sign of x.
  • gcd: Returns the greatest common divisor of a and b, which should be non-negative.
  • lcm: Returns the least common multiple of a and b, which should be non-negative; 0 when either is 0.
  • trunc: Removes the fractional part of x, rounding toward zero.
↑ ↓ navigate ↵ open