clamp
fn clamp<T: Ord>(T x, T lo, T hi) -> T Import
Source: use num::{clamp}; src/num.hy Returns x limited to the range lo..=hi.
Parameters#
| Name | Type |
|---|---|
x | T |
lo | T |
hi | T |
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 ofx.min: Returns the smaller ofaandb(awhen they are equal).max: Returns the larger ofaandb(awhen they are equal).round: Roundsxto the nearest whole number; halves round away from zero.signum: Returns-1,0or1by the sign ofx.gcd: Returns the greatest common divisor ofaandb, which should be non-negative.lcm: Returns the least common multiple ofaandb, which should be non-negative;0when either is0.trunc: Removes the fractional part ofx, rounding toward zero.