Given:
let a = 4.2 let b = -1.3 let c = 6.4
I want to know the simplest, Swiftiest way to clamp these values to a given range, say 0...
0...
Following up on @Fattie's answer and my comment, here's my suggestion for clarity:
extension Comparable { func clamped(_ a: Self, _ b: Self) -> Self { max(min(self, a), b) } }