Created
April 11, 2013 19:01
-
-
Save dropmeaword/5366232 to your computer and use it in GitHub Desktop.
signed maximum absolute
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
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