This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.abs() 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()" Watch "Math.abs()" New topic


Jiji Cherian

Joined: Apr 15, 2005
Posts: 14
Hi there.
This is a question related to Math.abs().
Why Math.abs(Integer.MIN_VALUE)and Math.abs(Long.MIN_VALUE)returns -ve value.
Looking forward for your valuable answers??
Thanks in advance..

Rgds.<br /> <a href="" rel="nofollow"></a>
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Jiji,

The negation of Integer.MIN_VALUE (-2147483648) will result in overflow since the range for int is -2147483648 to 2147483647. Same for long.

I agree. Here's the link:
subject: Math.abs()
Similar Threads
help with this Q
howto eliminate negative sign of number ?
Challenge: circular counter without conditional branches
Math.abs(Integer.MIN_VALUE)) not returning abs val
Where am I wrong??