Hacker News new | past | comments | ask | show | jobs | submit login

floats are one of the worst things that ever happened to computing, particularly when they use base 2 representation for the exponent. (eg. there is no "0.03" in the floating point numbers)



There’s no way to represent 1/3 as a decimal float. It’s a problem with any base.


Not a problem in bases divisible by 3.

It's exactly 0.1 in base 3 and 0.4 in base 12, for example.


That’s exactly my point. Every base has numbers it can represent that are not representable in other bases. Every base has numbers it cannot represent that are representable in other bases.


Come on, when I say 0.03 I mean 3/100 as in "3 cents".


Yes, and when I say 1/3, I mean 0.3333333333333333333333333333333333333333333333333333... and so on. Unfortunately, I can't tell you exactly, since we're using decimal.


As a workaround you simply approximate to a significant figure past any other values in your calculation. So in practice it doesn't really matter that there's no exact base-10 representation as a decimal because there's always an approximation that introduces no error.


So what's 1/3 + 1/3 + 1/3? If your answer is anything other than 1, you've introduced an error.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: