r/AskComputerScience • • Nov 23 '15

Do computers make calculation errors?

If computers can make billions of calculations per second, is there an expected calculation error rate they make? If so, is there some sort of correction process? If the calculations are really just tiny jolts of electricity going through logic gates, is there ever chance for an error? If I give excel 100,000 cells to perform a calculation on, is it possible for one of the calculations to be incorrect mathematically?

Thank you.

30 Upvotes

11 comments sorted by

View all comments

24

u/zombarista Nov 23 '15

The more pressing issue of incorrect calculation is that it is difficult to represent quantities like 1/3 with bits and so there are precision issues that programmers need to be constantly aware of. In finance, this is particularly problematic, so reliable software works in the smallest possible denomination of a currency. For example, you see $4.25, but the computer is working with this amount as 425 cents behind the scenes.

So the answer to the title question "Do computers make calculation errors?" is "yes, all the time" but not for any of the reasons you proposed.

Hope this helps.

15

u/panicnot42 Nov 23 '15

Not entirely correct. That's a matter of using correct data types. Floating point numbers are to be used as an approximation of a decimal value within a given precision. No sensible finance software will ever use a floating point point data type, as currency has a fixed precision. Floating point is used to maintain a certain level of precision at an arbitrary scale.

To answer OP's question, at a hardware level, yes, there may be faults, but they are exceedingly rare and more likely to manifest themselves as hard crashes or hangs, and much less likely as a few wrong decimal points in an excel sheet. At a software level, errors may creep in depending on how numbers are represented

2

u/zombarista Nov 23 '15

Good documentation of precision phenomena is here: http://0.30000000000000004.com/

2

u/panicnot42 Nov 23 '15

Well aware of floating point precision. But if you're having floating point precision errors, you're doing it wrong. They should only be used in a) performance critical code (eg graphics), where absolute precision is non important and b) areas where you must deal with irrational numbers. Almost every other case there is a better data type (but it may be overkill, depending on the use-case)