Floating point problem

Grant Edwards grant.b.edwards at gmail.com
Sat Apr 18 10:29:09 EDT 2020


On 2020-04-18, Souvik Dutta <souvik.viksou at gmail.com> wrote:
> I literally tried it!!! And it did not stop because I did not get any 1.0
> rather I got 0.99999999999 But why does this happen. This is a simple math
> which according to normal human logic should give perfect numbers which are
> not endless. Then why does a computer behave so differently?

Because computers _don't_do_math_.  That is a very important thing to
remember.

Computer do something that _approximates_ math... in some
situations...  if you know what you're doing.

In you're case you're doing IEEE floating point operations. Before you
use floating point, you should read the article by Goldman that has been
suggested:

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
https://dl.acm.org/doi/10.1145/103162.103163

--
Grant



More information about the Python-list mailing list