This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Bart van den Donk, ezio.melotti, mrabarnett, steven.daprano
Date 2019-01-04.13:01:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1546606884.3.0.373335113122.issue35658@roundup.psfhosted.org>
In-reply-to
Content
Not a bug. 0.1 is a binary floating point value, please read the FAQs:

https://docs.python.org/3/faq/design.html#why-are-floating-point-calculations-so-inaccurate

1/10 = 0.1 in decimal cannot be represented *exactly* in binary floating point, so when you type 0.1 as a float, the actual value you get is the closest number you can get using 53 bits for the significant digits, 8 bits for the exponent and 1 bit for the sign (plus or minus). That is approximately 0.1000000000000000056 or so.

Unfortunately you cannot get any closer to 1/10 in binary floating point numbers, for the same reason you cannot get 1/3 exactly in decimal.

See also 

https://stackoverflow.com/questions/8215437/floating-point-accuracy-in-python

https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate

https://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary?noredirect=1&lq=1
History
Date User Action Args
2019-01-04 13:01:26steven.dapranosetrecipients: + steven.daprano, ezio.melotti, mrabarnett, Bart van den Donk
2019-01-04 13:01:24steven.dapranosetmessageid: <1546606884.3.0.373335113122.issue35658@roundup.psfhosted.org>
2019-01-04 13:01:24steven.dapranolinkissue35658 messages
2019-01-04 13:01:24steven.dapranocreate