Skip to content

Instantly share code, notes, and snippets.

@dhasenan
Created April 12, 2018 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhasenan/8ac5301fc23666e0d181093819ad55cb to your computer and use it in GitHub Desktop.
Save dhasenan/8ac5301fc23666e0d181093819ad55cb to your computer and use it in GitHub Desktop.
clamp value with contracts
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