Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
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 ---------- nosy: +steven.daprano resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35658> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com