Created
February 1, 2014 14:15
-
-
Save vstakhov/8752923 to your computer and use it in GitHub Desktop.
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
| #include <stdio.h> | |
| #include <limits.h> | |
| int f(int x) | |
| { | |
| int y = x >> 31; | |
| return (x ^ y) - y; | |
| } | |
| void abs_test(int in) | |
| { | |
| printf("in=%d, abs=%d\n", in, f(in)); | |
| } | |
| int main (int argc, char **argv) | |
| { | |
| int x = -45, x0 = 100500, x1 = INT_MIN, x2 = 0, x3 = INT_MAX; | |
| abs_test(x); | |
| abs_test(x0); | |
| abs_test(x1); | |
| abs_test(x2); | |
| abs_test(x3); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment