Skip to content

Instantly share code, notes, and snippets.

@dropmeaword
Created April 11, 2013 19:01
Show Gist options
  • Save dropmeaword/5366232 to your computer and use it in GitHub Desktop.
Save dropmeaword/5366232 to your computer and use it in GitHub Desktop.
signed maximum absolute
int smaxabs(int a, int b) {
if((a < 0) && (b < 0)) {
return min(a, b);
} else if ((a < 0) && ( b > 0)) {
return ((abs(a) > b) ? a : b);
} else if ((a > 0) && ( b < 0)) {
return ((abs(b) > a) ? b : a);
} else {
return max(a, b);
}
}
int smaxabs(int a, int b, int c) {
int tmp = smaxabs(a, b);
return smaxabs(c, tmp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment