In the abs's man manual, there's a NOTES: Trying to take the absolute value of the most negative integer is not defined.
And the prototype of abs is:int abs(int j);
Why does abs return int
? As the return value will be positive, why not return unsigned int
?
If abs returned unsigned int
, the solution of the most negative integer's absolute value is simple like this:
if(INT_MIN == j)
return (unsigned int)j;