Created
April 12, 2018 02:33
-
-
Save dhasenan/8ac5301fc23666e0d181093819ad55cb to your computer and use it in GitHub Desktop.
clamp value with contracts
This file contains 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
T clamp(T)(T min, T max, T value) | |
in | |
{ | |
assert(min <= max); | |
} | |
do | |
{ | |
if (min > value) return min; | |
if (max < value) return max; | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment