7 ms·
My point is, this is elementary stuff that you need to know as a computer scientist or self-taught hacker. Whether you can convert a decimal number into its bi
by heresy 16y ago
My point is, this is elementary stuff that you need to know as a computer scientist or self-taught hacker.
Whether you can convert a decimal number into its binary IEEE-754 equivalent, or not, is besides the point.
You just need to know that it is lossy for certain classes of decimal numbers, and how to avoid or mitigate those effects.
- Cushman 16y agoSure, if you want to have computer hacking be a big part of your life you should know that numbers are binary on computers, and that that has side effects. But I don't think it betrays a serious lack of education that someone who does know that theoretically has never realized that practically means there's no such thing as 0.1 on a computer.
- jerf 16y agoYou theoretically shouldn't even have to be a computer scientist. A standard mathematical education ought to teach you that for any given base, the only numbers that can be represented in that base exactly are numbers where the prime factorization of the denominator contains only prime numbers that are also contained in the prime factorization of the base itself, or is simply 1 for integers. Base 10 has 2 and 5. .2 is 1/5, so it's precise. .5 is 1/2, so it's precise. 1/12 has 2 2s in it, which works, and a 3, which doesn't, so 1/12 is recurring. But prime factorization seems to be taught for almost superstitious reasons, as some sort of math trick rather than a fundamental aspect of understanding numbers at even the most basic of levels, with neither students nor teachers nor the curriculum writers really understanding why this is in the lesson plan, so, yeah, I suppose you have to be some sort of super expert genius to swiftly realize that 1/3 can't be represented in a base-2 number. But it shouldn't be that way.
- jrockway 16y agoI think the connection that "computer numbers are base 2" is what's missing. You input them into the computer in base 10, and they are printed in base 10. The base 10 representation is wrong because information was lost when converting to a fixed-width base 2 number. But that is hidden by the compiler or program, so it confuses programmers and users. It works in Excel...
- caf 16y agoExcel does "cosmetic" rounding, that ends up producing some surprising results - in the words of this author, it "confers supernatural powers upon some (not all) parentheses": http://www.cs.berkeley.edu/~wkahan/Mindless.pdf http://www.cs.berkeley.edu/~wkahan/Mindless.pdf
- drv 16y ago0.1 is perfectly representable "on a computer", just not in binary floating point.
- eru 16y agoSee e.g. Haskell's Data.Ratio (http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Data-Ratio.html http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0...) module for rational numbers.
- yock 16y agoWell, if you take Java for example, floating point measurements are only IEEE-754 when classes or methods are declared with the strictfp keyword, yet non-strictfp floating point calculations are still imprecise because of the very nature of fractional math. They're just less imprecise by default. I agree with the sentiment others have posted that it is disappointing that this reality isn't more commonly taught in CS education.