I know this will really turn out to be simple, but my brain is just not working. I need a function in C# that will return -1 if the integer passed to the function has a nega
public int SignFunction(int number) {
return (number > 0) ?
1 : (number < 0) ?
-1 : number;
}
return input.CompareTo(0);
int sign = Math.Sign(number);
It already exists.
public int Sign(int number)
{
if(number==0)
return 0;
return number/Math.Abs(number);
}
If Math.Sign
did not exist, I would do this:
return x == 0 ? 0 : x / Math.Abs(x);
public int SignFunction( int input )
{
if( input < 0 ) return -1;
if( input > 0 ) return 1;
return 0;
}