Skip to content

Instantly share code, notes, and snippets.

@st98
Last active August 29, 2015 14:01
Show Gist options
  • Save st98/1fbdcc1c652f56ea3adc to your computer and use it in GitHub Desktop.
Save st98/1fbdcc1c652f56ea3adc to your computer and use it in GitHub Desktop.
絶対値。
#include <stdio.h>
int _abs(int n) {
return n & (1 << (sizeof(int) << 3 - 1)) ? ~n + 1 : n;
}
int main(void) {
printf("_abs(%d) = %d\n", -12, _abs(-12));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment