Skip to content

Instantly share code, notes, and snippets.

@Const-me Const-me/ffx.cpp
Last active Nov 12, 2016

Embed
What would you like to do?
#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
You can’t perform that action at this time.