Live data from Hacker News

Floating Point Math

0.30000000000000004.com

1–10 of 67 posts

Re: Floating Point Math

#3
It'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 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

#4
We 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

#7

previous discussions: https://news.ycombinator.com/from?site=30000000000000004.com

Thanks! Macroexpanded:

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

#8
post #3

It'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…

> it can only express fractions that use a prime factor of the base.

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

#9

Why don't we store fractions as fractions rather than floating point?

Finding a reasonably accurate fractional approximation to a number, even allowing a certain degree of suboptimality in the estimation, is not computationally efficient. So, computing with fractions almost immediately becomes computing with bigints, unless you get lucky and stuff cancels out.

Re: Floating Point Math

#10

We 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?

Rational numbers can also be trated as quotient of two integers and stored with arbitrary precision by storing these two values, even with limited precision of 2x32 bit integers, that would perfectly accurately capture 1/3 and 1/10.

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".

Post reply on HN