5 ms·
You know how you can't store 1/3 in decimal. (I think I learnt that in primary school) Same case with 1/10 to binary. Discussion Over. How does this story h
by adaml_623 14y ago
You know how you can't store 1/3 in decimal. (I think I learnt that in primary school)
Same case with 1/10 to binary.
Discussion Over. How does this story have any up votes?
- erichocean 14y agoI asked the same thing, and got so many downvotes I had to quickly delete it! The ways of HN are strange, sometimes.
- pavel_lishin 14y agoThe key word in your first sentence is "store". A lot of people, when they're starting out, have no idea how computers store digits. I can easily store 1/3 in decimal - 0.3 with a bar over the 3. But, as the article points out, computers don't store bars. But did you learn that on the first day that you sat down at a computer?
- mfonda 14y agoI think it's a great article and it's nice to see a that it has up votes, as a lot of programmers, including those without a computer science background, have no idea about binary or how computers represent decimals. The article opens with a good summary of the problem: Questions [about floating point issues] are asked every day, on online forums like stackoverflow.com. The answer is that most decimals have infinite representations in binary.
- dbaupp 14y agoJust because something is obvious to one person, it doesn't mean every person has considered it long enough to make the connection between them. This article might just make a whole bunch of people "click", and understand why they are getting unexpected results. (There's no need to be aggressive about it!)
- nollidge 14y agoNot everyone around here is a programmer, or has really thought about how fractions are represented in binary.
- greyfade 14y agoIn fact, it's something that should be pounded into the skulls of programmers at every opportunity. It's something we tend to forget often enough (if we learned it) that we should be reminded of it frequently.
- juan_juarez 14y agoThe standard answer to programming noobs is "What Every Computer Scientist Should Know About Floating-point Arithmetic". http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.ht...
- rockmeamedee 14y agoI found it insightful. Why can't you write down 1/10 in binary? What is 1/10 in binary? OP calculates it, and then explains that any fraction in reduced form in which the denominator is a power of 2 will terminate in binary. (Powers of 5 and 2 for decimal). These are interesting bits of trivia.
- kmfrk 14y agoYour comment is exactly why getting into programming for the first time is a shit experience for many people. I even had Ph.D. TAs in college with the same attitude. Unbelievable.
- kevhsu 14y agoThis is the type of thing I learned in my first semester of undergrad as a CompE. This information is not a revelation for 90% of people with programming experience unless I'm greatly overestimating our collective knowledge.
- adaml_623 14y agokmfrk: You have a point. I guess my point was that _I_ don't think HN is a venue for sharing articles aimed at beginners. But the upvotes prove me wrong :) The article is pretty well written.