• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compound assignment operator- cast

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends,

in this piece of code:



output:

(int)d : -2
absolute val of d: 2.9
(int)absolute val: 2
i*= (int)(Math.abs(d): -4
(int)(-2* Math.abs(d)) : -5

i thought the last two statements would give the same output...
but looks like in the *= statement does the cast on each element and then gives the output... while the last statement does the cast on the whole result...

is this how it is supposed to happen?... i always thought the cast is performed after the operands are evaluated.. am i wrong?

thanks in advance
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
No, everything is OK :
with d = -2.9 :
(int)(-2* Math.abs(d)) => (int)(-2.0 * +2.9) => (int)(-5.8) => -5
reply
    Bookmark Topic Watch Topic
  • New Topic