aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.abs(Integer.MIN_VALUE)) not returning abs val Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.abs(Integer.MIN_VALUE)) not returning abs val" Watch "Math.abs(Integer.MIN_VALUE)) not returning abs val" New topic
Author

Math.abs(Integer.MIN_VALUE)) not returning abs val

kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
HI All
In the following code why the last line's output is so

int k=Integer.MAX_VALUE;
System.out.println("Integer.MIN_VALUE \t" + Integer.MIN_VALUE);
System.out.println("Math.abs( k )\t" + Math.abs(k));
System.out.println("Math.abs( Integer.MIN_VALUE )\t" + Math.abs(Integer.MIN_VALUE));
output is:
Integer.MIN_VALUE -2147483648
Math.abs( k ) 2147483647
Math.abs( Integer.MIN_VALUE ) -2147483648

Thanks
kundan


SCJP1.4,SCBCD,SCEA,CNA
Failures are practice shoots for success.
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
Look into the java api,
API
it says for the abs method of Math class:

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.

So, u get such output.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math.abs(Integer.MIN_VALUE)) not returning abs val
 
Similar Threads
java.lang.Math
jquest question!!!!!!!!
Math.abs(Integer.MIN_VALUE) return a negative vaue,why?
Why Math.abs() is giving negative output??????
question about Math class