[sf-lug] Old Calculator Problems

Sujit K M kmsujit at gmail.com
Thu Aug 11 07:32:06 PDT 2016


On Thu, Aug 11, 2016 at 10:19 AM, Sujit K M <kmsujit at gmail.com> wrote:
> I found something wron in your stackover link. Python lets you round
> to 10 pow -15.

Yeah if you add 0.1 with any number there is an result in these terms.
>>>0.1+0.2 = 0.30000000000000004.

Similarly
>>>0.7 + 0.2 = 0.8999999999999999

Also
>>> 0.1

0.1 This is because python prints what ever it is keyed, but has trouble using
the internal representation to do arthemetic which leads to errors
mentioned in this
mail. This is not exactly a software issue to. It is more to do with
Floating Point
hardware in question.

Quote form Python.org.

"Why is that? 1/10 and 2/10 are not exactly representable as a binary
fraction. Almost all machines today (July 2010) use IEEE-754 floating
point arithmetic, and almost all platforms map Python floats to
IEEE-754 “double precision”. 754 doubles contain 53 bits of precision,
so on input the computer strives to convert 0.1 to the closest
fraction it can of the form J/2**N where J is an integer containing
exactly 53 bits. Rewriting"




More information about the sf-lug mailing list