Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why float == long  RSS feed

 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

can any body please tell me why in code
5.0==5L

then answer is true !!!
I know variables contains bits representing the value and here above 5.0 ( i think its double ) is equal to 5 ( long ) why ?
is it because both are 64 bits..

but what about long store decimals in bits.. how it can be same ?
pls reply

thanx and regards
amit
 
Akash Roy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
During == operator i think long gets promoted to float as 5.0 and hence the == operator returns true. The same can be observed during comparisons of the following types:=

int == long
short == byte
float ==double

Regards,
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!