There is a sign function in C:
int sign(int x)
{
    if(x > 0) return 1;
    if(x < 0) return -1;
    return 0;
}
Unfortunately, comparison cost is very high, so I need to modify function in order reduce the number of comparisons.
I tried the following:
int sign(int x)
{
    int result;
    result = (-1)*(((unsigned int)x)>>31);
    if (x > 0) return 1;
    return result;
}
In this case I get only one comparison.
Is there any way to avoid comparisons at all?
EDIT possible duplicate does not give an answer for a question as all answers are C++, uses comparison (that I supposed to avoid) or does not return -1, +1, 0.
 
     
     
     
     
     
     
    