Floating Point Math
0.30000000000000004.com
Floating Point Math
1–10 of 67 posts
Re: Floating Point Math
#2Re: Floating Point Math
#3The only sentence I don't really like:
> When you have a base-10 system (like ours), it can only express fractions that use a prime factor of the base.
It's a weird mix of over- and under-generalization. The second half sounds like a feature of all number systems independent of the base, and we can express more numbers (just with a notion of 'repeating infinitely' or as fractions), that's why they even switch to "expressed cleanly" in the next sentence.
If I get more sleep and can think of a good way to express it, maybe I'll actually make a pull request ;)
Re: Floating Point Math
#4Re: Floating Point Math
#5We all know this by now right? We know computers store numbers in binary (unless using BCD) and numbers like 1/10 and 1/3 can only be approximated in a finite number of bits. This isn't news is it?
Re: Floating Point Math
#6Re: Floating Point Math
#7previous discussions: https://news.ycombinator.com/from?site=30000000000000004.com
0.1 and 0.2 = 0.3 - https://news.ycombinator.com/item?id=28390997 - Sept 2021 (2 comments)
0.30000000000000004 - https://news.ycombinator.com/item?id=21686264 - Dec 2019 (402 comments)
0.30000000000000004 - https://news.ycombinator.com/item?id=14018450 - April 2017 (130 comments)
0.30000000000000004 - https://news.ycombinator.com/item?id=10558871 - Nov 2015 (240 comments)
Re: Floating Point Math
#8It's a nice website explaining the problem lightly, but I think the cool part is the encyclopedic language list handling floating point numbers and the reference for bigdecimal support. The only sentence I don't really like: > When you have a base-10 system (like ours), it can only express fractions that use a prime factor of the base. It's a weird mix of over- and under-generalization. The second half sounds like a…
IMO it could do better to explain why this is the case rather than state it as a fact, as it’s not immediately obviously true (at least to me).
A terminating decimal is equivalent to a fraction with a denominator that is a power of 10. Any fraction with a denominator that is a product of prime factors of 10 can be turned into a fraction with a denominator that is a power of 10. Thus the only fractions with terminating decimal representations are those with denominators which are a product of prime factors of 10.
Of course this is true for any base other than 10, but I couldn’t think of a term for “terminating decimal” with other bases.
Re: Floating Point Math
#9Why don't we store fractions as fractions rather than floating point?
Re: Floating Point Math
#10We all know this by now right? We know computers store numbers in binary (unless using BCD) and numbers like 1/10 and 1/3 can only be approximated in a finite number of bits. This isn't news is it?
But I also don't think it is particularly 'news', the discussion on previous versions centered around the problems that arise from floats, such as inconsistent handling by tools and languages and 'inapropriate use' where the precision from floats is not good enough or misleading. So maybe it is more a "topic of interest".