-2

2.333333333333333 - 1.666666666666667 It appends 1 in the last, increasing one bit. How to resolve it.

In the answer its giving, 0.6666666....1, but it should be 0.66666....6

  • 2
    give explanation to your question.. make it clear to us. – Setu Kumar Basak Feb 27 '16 at 07:33
  • In the answer its giving, 0.6666666....1, but it should be 0.66666....6 – SARFRAZ AHMAD Feb 27 '16 at 07:43
  • 1
    Welcome to Stack Overflow. Your question doesn't give us enough detail in order for us to give you an answer. At a minimum, you should post a relevant sample of your code and the exact result you are getting. I encourage you to take the [tour](http://stackoverflow.com/tour) and to visit the [help center](http://stackoverflow.com/help/asking) for guidance on asking good questions on this site. – McMath Feb 27 '16 at 07:43
  • 1
    Please read [What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html). The computer cannot represent numbers with arbitrary precision when using `float` or `double`. – Jim Garrison Feb 27 '16 at 08:10

1 Answers1

-2

I am going to guess you meant.6666...7 but it should be .6666...6 if you plan on programming I would strongly recommend that you learn how software interacts with the hardware. When a computer stores memory it cannot save the same amount of positive numbers as negative numbers. The reason being that the computer uses somthing of the format like,

10000001111

For (this is in binary) negative numbers where the one in front indicates that it is negative while,

00000001111

is the positive version of the same number (the absolute value for all you math nerds). Seeing this you should realize that you can store more positive numbers than negative numbers, so you need to be careful with whatever type you are using. However since your question is not 100% clear I cannot guarantee this will 100% answer your question. Good luck...