Created
January 13, 2016 03:13
-
-
Save wudi/af6a787923ddb5efd248 to your computer and use it in GitHub Desktop.
nagative or positive
This file contains hidden or 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
//ref: http://stackoverflow.com/questions/33882676/why-intunsigned-intintv | |
int compare(int x) | |
{ | |
return -(int)( | |
(unsigned int)( (int) x ) >> ( sizeof(int) * CHAR_BIT - 1 ) | |
); | |
} | |
//equal to | |
int compare(int x) | |
{ | |
return (x < 0) ? -1 :0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment