Ever needed a stripper? A SIGN stripper? Go on, get your positive juices flowing.
This is the one that tend to be on the market, sure it works, but we can do better can't we?
int abs (int number)
{
if (number < 0) return 0 - number;
else return number;
}
then call with:
posnum = abs(num);
So I present the new, improved, reliant on dodgy defines version!
#define _ISIGN & 2147483648 / 1073741824 + 1
then call with:
posnum = num * (num _ISIGN);
And the speed? My estimates are 3-5 times as fast. On my testbed:
//Blank; 371ms
posnum = num; 645ms
posnum = num * (num _ISIGN); 1011ms
posnum = abs(num); 3173ms
Thankyou and goodnight.
Zip