Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math.abs()

 
Jiji Cherian
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Joyce
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic