• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange output from java  RSS feed

 
Ranch Hand
Posts: 48
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I would like to know why my code is giving me such strange output :



OUTPUT :

65534
65534
-2
Infinity
Infinity
0.7999999999999999
0.8
Press any key to continue . . .


Why do i get the strange results: -2 , infinity , 0.7999 ?
Seems to be a concept I'm not aware of?

Thanks
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those concepts are two's complement and floating point arithmetic.
 
Sheriff
Posts: 11495
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray mann wrote:
Seems to be a concept I'm not aware of?

Read through some of the results of these searches:

Floating point precision error
How computers represent numbers
size of int in Java
size of long in Java
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:Those concepts are two's complement and floating point arithmetic.


Correct. For integers, it would require a discussion regarding the twos complement format / standard. And for floating point, it would require a discussion regarding the IEEE 754 format / standard.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!