Last active
November 12, 2016 21:14
-
-
Save Const-me/a37625a1b2fc5129ee5bb94f583aba7d 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 "stdafx.h" | |
int f( int x ) | |
{ | |
if( 0 == x ) | |
return 0; | |
if( 0x80000000 == x ) | |
return 0x80000001; | |
const int c = ( ( x >> 31 ) & 1 ) * -2 + 1; | |
const int mul = ( x & 1 ) * 2 - 1; | |
return c + x * mul; | |
} | |
int main() | |
{ | |
int tests[] = | |
{ | |
-12, -11, 0, 7, 8 | |
}; | |
for( int i : tests ) | |
{ | |
printf( "%i\t%i\t%i\n", i, f( i ), f( f( i ) ) ); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment