Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Round

 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The output is -2147483648 . Could anyone please explain how?
- Thanks
[I added UBB CODE tags to your source code to make it more readable. Please try to use them in the future - Ajith]

[This message has been edited by Ajith Kallambella (edited August 31, 2000).]
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
round() method return int (if an input parameter is float), and -2147483648 is the minimal possible value for int variables.
(try System.out.println(Integer.MIN_VALUE); )
 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How do u remember all these numbers? Do u have any notes or pointer where it is explained well?
like Math.ceil(Double.Max_Value)
Math.ceil(Double.NaN) etc
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I remember all these numbers - good question! Actually it would be nice if I did not have to. Round() method could somehow warn us that input parameter is too big, uh? For what purpose did Java designers created all these exceptions, if they do not use them themselves?
When I started to work as a computer programmer, the basic rule was: �user will have either correct result or no result at all�. In your case round() method produces incorrect result. For me it is the worst decision, java designers could make. Maybe I am mistaken � Java experts, moderators, all you guys with CS Master degree, correct me!
I am afraid you have to have very good memory (loaded with tonns of small details) if you are going to pass the exam.
Notes: I have only this URL: http://www.geocities.com/SiliconValley/Network/3693/obj_sec9.html#obj28
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic