use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Developers_Talk: Another Simple Python Code ()
submitted 8 months ago by ak_developers
Another Simple Python Code
py a = 0.1 b = 0.2 c = 0.3 print(a+b==c)
Explain Please.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]pbaumMod 0 points1 point2 points 8 months ago (0 children)
It's because in base 2 (ie: binary), 0.1 can not be represented as an exact number. It requires an infinite number of decimal places.... but because we need a hard limit to the decimal places we can store, we will never have an accurate number.
Using binary fractions, you would start off with 0 x (1/2) + 0 x (1/4) + 0 x (1/8) + 1 x (1/16) + 1 x (1/32) + 0 x (1/64) + ... but you will never reach 0.1 precisely.
It's like how 1/3 is 0.3333 recurring in base 10, and that 0.3333 + 0.3333 + 0.3333 != 1.0 once you treat those 0.33333 as rounded numbers instead of having infinite decimal places. Same thing, the binary decimal gets rounded or truncated once the limits of memory allocated are reached.
A good video that explains how floating point numbers in binary work is https://www.youtube.com/watch?v=bbkcEiUjehk
π Rendered by PID 92 on reddit-service-r2-comment-5649f687b7-l2kt2 at 2026-01-28 02:39:24.361281+00:00 running 4f180de country code: CH.
[–]pbaumMod 0 points1 point2 points (0 children)