so with this there cant be any short or byte or char....right ..
Right for no short or byte MIN_VALUE returned from abs(). But yes for char since char is unsigned 16 bits. Thus Character.MIN_VALUE is '\u0000' which casts to int 0 and abs(0) is 0.
Integer.MIN_VALUE
Long.MIN_VALUE these must be negative right then how can abs return me negative??
Has to do with binary math. Here is abs() code:
public static int abs(int a) {
return (a < 0) ? -a : a;
}
So when Integer/Long.MIN_VALUE used the return value is (-a) or
the negation of the argument is returned. (from API). So the two's complement of the parameter is returned. Looking at the bit
pattern:
Integer.MIN_VALUE = -2147483648, or in hex = 80000000
and the two's complement of 80000000 is the same number!