Created
January 4, 2018 11:30
-
-
Save laevandus/6fd35992157fcc9b5660bcbc82ebfb52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension FloatingPoint { | |
func clamped(to range: ClosedRange<Self>) -> Self { | |
return max(min(self, range.upperBound), range.lowerBound) | |
} | |
} | |
let clamped = 5.4.clamped(to: 5.6...6.1) | |
let clamped = 10.5.clamped(to: 5...7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment