Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Jeanne Boyarsky
• Bear Bibeault
Sheriffs:
• Rob Spoor
• Henry Wong
• Liutauras Vilda
Saloon Keepers:
• Tim Moores
• Carey Brown
• Stephan van Hulst
• Tim Holloway
• Piet Souris
Bartenders:
• Frits Walraven
• Himai Minh
• Jj Roberts

Integer.Min_value

Ranch Hand
Posts: 817
• Number of slices to send:
Optional 'thank-you' note:
hii
in one of the dan explaination to question...there is written that

If the argument is a negative integral value, then the returned value is the two's complement of the argument. The magnitude of Integer.MIN_VALUE is one greater than the magnitude of Integer.MAX_VALUE; therefore, the absolute value of Integer.MIN_VALUE exceeds the range of Integer.MAX_VALUE. Due to the limited range of type int, the two's complement of Integer.MIN_VALUE is Integer.MIN_VALUE. For that reason, the Math.abs method returns Integer.MIN_VALUE when the argument is Integer.MIN_VALUE. The negation of Short.MIN_VALUE is well within the range of type int; so Short.MIN_VALUE is never returned by the Math.abs method.

i m not able to understand fully what does that means...
if anybody pls explain me with eg. would be gr8 help to me...

Sheriff
Posts: 11343
• Number of slices to send:
Optional 'thank-you' note:
The range of an int is -2^31 to (2^31)-1, which is -2147483648 to 2147483647. Note that the magnitude of the negative bound is one greater than that of the positive bound.

So the absolute value of Integer.MIN_VALUE is actually greater than Integer.MAX_VALUE. In particular, we might expect the absolute value to be +2147483648, but this is one greater than what can be expressed as a positive int, so this overflows to Integer.MIN_VALUE.

In terms of twos complement, flipping the bits of Integer.MIN_VALUE results in Integer.MAX_VALUE, then adding 1 causes the overflow. Note the output from the code below...

This is not a concern when a short is passed to the Math.abs(int) method, because the short is widened to type int, which can easily accomodate Short.MAX_VALUE + 1.
[ May 12, 2005: Message edited by: marc weber ]

 What are your superhero powers? Go ahead and try them on this tiny ad: SKIP - a book about connecting industrious people with elderly land owners https://coderanch.com/t/skip-book