Untitled (https://0.30000000000000004.com/)

50 bookmarks. First posted by mootcycle october 2017.

Your language isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with

programming
2 days ago by bjcubsfan

Handy web page that explains the issue of floating point numbers, as it relates to different programming languages.

programming
2 days ago by davep

RT @emax: oh wow, this should have been obvious but shows how much living in a binary world can be unpredictable >

from twitter
3 days ago by noii

how is this real how did this happen what did you do enom what did you do there are no letters there are no words

math
3 days ago by yizhexu

Your language isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, .1 + .2 != .3.

Why does this happen?

It's actually rather interesting. When you have a base 10 system (like ours), it can only express fractions that use a prime factor of the base. The prime factors of 10 are 2 and 5. So 1/2, 1/4, 1/5, 1/8, and 1/10 can all be expressed cleanly because the denominators all use prime factors of 10. In contrast, 1/3, 1/6, and 1/7 are all repeating decimals because their denominators use a prime factor of 3 or 7. In binary (or base 2), the only prime factor is 2. So you can only express fractions cleanly which only contain 2 as a prime factor. In binary, 1/2, 1/4, 1/8 would all be expressed cleanly as decimals. While, 1/5 or 1/10 would be repeating decimals. So 0.1 and 0.2 (1/10 and 1/5) while clean decimals in a base 10 system, are repeating decimals in the base 2 system the computer is operating in. When you do math on these repeating decimals, you end up with leftovers which carry over when you convert the computer's base 2 (binary) number into a more human readable base 10 number.

https://news.ycombinator.com/item?id=21686264

math
binary
Why does this happen?

It's actually rather interesting. When you have a base 10 system (like ours), it can only express fractions that use a prime factor of the base. The prime factors of 10 are 2 and 5. So 1/2, 1/4, 1/5, 1/8, and 1/10 can all be expressed cleanly because the denominators all use prime factors of 10. In contrast, 1/3, 1/6, and 1/7 are all repeating decimals because their denominators use a prime factor of 3 or 7. In binary (or base 2), the only prime factor is 2. So you can only express fractions cleanly which only contain 2 as a prime factor. In binary, 1/2, 1/4, 1/8 would all be expressed cleanly as decimals. While, 1/5 or 1/10 would be repeating decimals. So 0.1 and 0.2 (1/10 and 1/5) while clean decimals in a base 10 system, are repeating decimals in the base 2 system the computer is operating in. When you do math on these repeating decimals, you end up with leftovers which carry over when you convert the computer's base 2 (binary) number into a more human readable base 10 number.

https://news.ycombinator.com/item?id=21686264

3 days ago by danwin

Your language isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, .1 + .2 != .3.

programming
mathematics
3 days ago by Chirael

RT @rauschma: If anyone complains about JavaScript being weird, because 0.1 + 0.3 !== 0.4, send them to this website:

from twitter_favs
may 2019 by amitkaps

RT @rauschma: If anyone complains about JavaScript being weird, because 0.1 + 0.3 !== 0.4, send them to this website:

from twitter_favs
may 2019 by rtanglao

Your language isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, .1 + .2 != .3.

mathematics
programming
error
may 2019 by mark.larios

If anyone complains about JavaScript being weird, because 0.1 + 0.3 !== 0.4, send them to this website:

from twitter_favs
may 2019 by matthewbeta

If anyone complains about JavaScript being weird, because 0.1 + 0.3 !== 0.4, send them to this website:

from twitter_favs
may 2019 by akalin

If anyone complains about JavaScript being weird, because 0.1 + 0.3 !== 0.4, send them to this website:

from twitter_favs
may 2019 by mehulkar

RT @dakami: how is this real how did this happen what did you do enom what did you do there are no letters there are no words

from twitter
october 2017 by mlp

how is this real how did this happen what did you do enom what did you do there are no letters there are no words

from twitter_favs
october 2017 by mootcycle

tags

binary compsci decimal dev development error everynumber float floating-point-numbers floating-point floating floatingpoint floatingpointmath floating_point floatpoint fun humor ieee754 interesting javascript learning math mathematics number point precision progamming programming python reference software tools tutorial via:popular workflow