public static void main (String[] args) { System.out.print(Integer.MIN_VALUE == Math.abs(Integer.MIN_VALUE)); } 1. Why the output is true for Integer,Long,Double,Float. 2. The abs() should strip -ve sign for Integer,Long,Double. i.e Math.abs(Integer.MIN_VALUE) 3.Why is it stripping off -ve sign only for Short and Byte. 4. What is the value of MIN_VALUE,MAX_VALUE for Float,Double. Thanks
Hi Suresh, The API notes the following for Math.abs(Integer.MIN_VALUE) .....Note that if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative. Ditto for Long As for Double & Float remember that Float.MIN_VALUE & Double.MIN_VALUE are positive values so you get the same result. HTH Ashish H.
I'm not from a CS background ( Chem actually ) so I really take the word of the API for granted , period. I really don't know why the makers of Java did so.Maybe someone else here can enlighten us