git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Floating point problem


On 18/04/2020 15:29, Grant Edwards wrote:
> 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

There is also

https://docs.python.org/3/tutorial/floatingpoint.html

In the official Python documentation, well worth reading.

>
> --
> Grant
>