Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

primitive datatypes

 
Aneeta Srini
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this in Mughal's book.

He says that we need to ensure that the values that are multiplied really are multiplied using long datatypes, not multiplied as int datatypes
and later converted to long. The L suffix on the 1000L integer literal ensures this.
My question is what difference does it make if they they are multiplied as int datatypes and later converted to long??
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you compute 150000000 * 1000 as integer the result will be bigger than Integer.MAX_VALUE.
Actually if you compile the code and run it, you can see that mFromSun yields -323855360
However, if you compute the value as a long you get the correct result...
 
Aneeta Srini
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot ! I now understand
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic