Skip to content

Instantly share code, notes, and snippets.

@wudi
Created January 13, 2016 03:13
Show Gist options
  • Save wudi/af6a787923ddb5efd248 to your computer and use it in GitHub Desktop.
Save wudi/af6a787923ddb5efd248 to your computer and use it in GitHub Desktop.
nagative or positive
//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