Hacker News new | ask | show | jobs
by slimscsi 2398 days ago
Thanks for the comment. For the record, I am very aware of iee 754, And I am aware that some numbers that have infinite repetition in decimal can have an exact representation. I actually thought about pointing that out. However I decided that it didn't add much to the post. It was written for more of a general audience and diving into those details, while would make the post more technically correct, would not actually add any value for the average reader.
4 comments

I don't want to come off as combative, but I would argue that a correction would add quite a bit to the post. What you have is straight-up incorrect and wouldn't even take that much effort to fix. "For a computer to store the decimal representation a number that repeats forever would require an infinite amount of memory, so the number is approximated" would be correct and it's just a couple words more.
Agreed.
I agree. This is a small change that makes the statement true.
There are uncountably infinite real numbers and countably infinite rational numbers, so we cannot represent all of them using a {0, 1}^n where n is a finite number. No matter which numbers you can exactly represent, there will always be uncountably many real numbers which are not exactly representable, and, conversely, the set of real numbers exactly representable using a finite number of bits will have measure zero.
With all due respect, you sound like you don't understand the difference between rational and real numbers.

Also, the 'decimal' part of your comment is not needed, number base is irrelevant here.

The issues of "repeating decimal" and exact representation as a floating point number are orthogonal. Because the mantissa in a floating point number (which is fixed width) is in base 2, only fractions with denominators that are powers of two can be exactly represented. This means that simple base-10 decimals like 0.1 cannot be exactly represented by a float. For this reason it's at least a bit misleading to talk about how some numbers cannot be represented with finite memory, and then go straight into a demonstration of how they can in fact be represented in finite memory (as a fraction).

As for the comment about a general audience, if (some of) your target audience is HN readers, I think it's reasonable to expect many readers to be familiar with computer science.

If this were my article, I would replace the paragraph in question with a discussion of the error introduced in floating point calculation — consider perhaps that many programming languages will tell you 0.1 + 0.2 = 0.30000000000000004 [0].

[0]: https://0.30000000000000004.com/

Thanks again for the refresher. But again I am keenly aware for how floating point works. As for audience, this is not a hacker new exclusive. It just happens to be here rite now. It will probably make rounds in other forums as well. If you want to write an post an article on how floating point works. I’ll be happy to read it!
I know this sort of criticism can be annoying, but despite commenting on HN I would surely qualify as a 'lay reader' in this context, and I have a strong preference for authors taking care to either tell the whole truth or flag that a potentially misleading simplification has been made -- even if the falseness seems like a technicality to the author. If I notice it then I lose faith in the author's credibility, and if I don't then now I've 'learned' something false.
I enjoyed the article. Please ignore the nitpicking that goes on around here.