• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boundary Values

 
Kanchan K Bulbule
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering why
-----------------------------------------
Integer.MIN_VALUE -1 = Integer.MAX_VALUE
Integer.MAX_VALUE + 1 =Integer.MIN_VALUE
-----------------------------------------
and the same is true for Long !!!
But not for Double and Float may be they represent floating point numbers.

Any clue...?


Cheers
Kanchan
 
Priya Jothi
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is because once it(int or long) exceed its range it starts to wrap over the opposite range of values.
 
Abhishek Jain
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would like to add more

2S representaiton for Number type
=================================
how 2s addition works...
E.G.
taking 8 bit number and it can be extended for 32 bit integer

max 8 bit no=01111111=127
01111111
+00000001
-------------
10000000

now hows 10000000 treated by compiler
compiler after seeing one as left most bit would assure no is -ive
and would convert that value using 2s complemnt

01111111 one 's complement
now add 1 to it this would be the value
ie
10000000 128 but with -ive sign

hence Max8bitno+1=Min8bitNo

got it.........

but this kind of representation is not there for float and double
they are having seperate rep for mantisaa and exponent so they dont work
in this way

Regards
Abhishek
 
Kanchan K Bulbule
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the gr8 Explanation .

Cheers
Kanchan
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the gr8 Explanation .


Please make the extra effort to write out words such as "great". The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.

http://faq.javaranch.com/view?UseRealWords
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Along those lines, someone pointed out that he'd read that as "gracht". This led me to the somewhat amusing "grocho". Then I remembered my Italian lessons and "grotto", which actually *does* carry a genuine meaning in English as well.

Then, I just got silly.
http://www.travlang.org/wordofday/110.html

At least in Esperanto, I can grok what he was talking about...
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic