Computer Science – How Do Calculators Represent Floating Points Perfectly?

calculatorcomputer sciencefloating point

If you ask a programming language to calculate 0.6 + 0.7, you’ll get something like 1.2999998, and that’s because of how floating point numbers are represented in computers. But if you ask a calculator, or even the calculator app on your phone, to do the same thing, it will give you the correct answer: 1.3. Why? Do calculators not represent floats the same way that other computers do?

Best Answer

The short version is, they're cheating. Calculators or calculator apps are, if anything, less capable than computers and programming languages in general. That said, they're also specialized for doing exactly that sort of thing, so they're more inclined to take 12.9999998 and round it for you to 13. Programming languages will do the same thing, but depending on which language and how precise the number, you might have to ask them to.

Take any calculator and try something like adding $1+10^{-100}-1$, and in my experience, you'll get $0$, not $0.0000\dots 001$.