diff --git a/src/lib.rs b/src/lib.rs index 77b34c3..14bb02d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,3 +109,10 @@ pub mod traits { pub mod rational { pub use num_rational::*; } + +pub fn clamp(input: T, min: T, max: T) -> T { + debug_assert!(min < max, "min must be less than max"); + if input < min {min} + else if input > max {max} + else {input} +}