This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

+ operator

 
Ramya Iyer
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to understand a particular explanation of the + operator. Can some one provide example to throw light on this?

For a + expression with two operands of primitive numeric type, the result
has a value calculated by promoting the operands to the result type and then performing the addition using that type. This might result in overflow or loss of precision.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java, meaning the compiler and runtime system, will not (I think never) tell you that an overflow might occur.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramya Iyer:
... Can some one provide example to throw light on this? ...

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if the question was about "promoting the operands to the result type". See if this example makes sense:

I think these show your statement was possibly misleading. The operands are not promoted to the declared type of the result variable but to the widest operand which becomes the actual result of the expression.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
I wonder if the question was about "promoting the operands to the result type"...

Good call. I missed that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic