Skip to content

Instantly share code, notes, and snippets.

@skjalgsm
Created October 26, 2016 08:17
Show Gist options
  • Save skjalgsm/2401e5aef1b648155c5c9bb03427a43e to your computer and use it in GitHub Desktop.
Save skjalgsm/2401e5aef1b648155c5c9bb03427a43e to your computer and use it in GitHub Desktop.
static public int Max(int a, int b) {
a -= b;
a &= (~a) >> 31;
return a + b;
}
static public int Min(int a, int b) {
a -= b;
a &= a >> 31;
return a + b;
}
static public uint Clamp01(int n) {
return Max(Min(n, 1), 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment