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

14

u/zedoriah Nov 23 '15

You're interested in Error Detection and Correction. The wiki does a good job of explaining it and includes several different types of errors that can occur, and the methods used for detecting and fixing them.

14

u/LimivorousArbour Nov 23 '15

Spontaneous errors can occur due to cosmic rays or hardware defects. Cosmic ray errors are something you can observe if you have large numbers of machines running calculations around the clock for extended periods, see e.g. the google study DRAM Errors in the wild.

It would be exceedingly unlikely to observe a calculation error in a modest spreadsheet on a single machine due to a cosmic ray. Especially if you are using ECC memory.

I've seen a calculation error caused by faulty hardware. We eventually tracked down the problem by noticing that all the failures occurred on a particular cloud machine, and hardware diagnostics turned up a single faulty memory bit. We weren't using ECC RAM, a problem we've since corrected.

9

u/[deleted] Nov 23 '15

There are basically two kinds of errors that can corrupt your computation results: systematic errors caused by bugs in the design of hardware and software, and random errors caused by the environment.

Systematic errors are just that—bugs that are baked into the design of the hardware and software. Errors like the famous Pentium floating point division bug, overflow and underflow problems, rounding errors, and plain old logic errors, fall into this category. These errors are deterministic, i.e. given a particular initial system state they will always occur, and produce the same erroneous result.

Random errors are introduced by flaws in silicon, environmental factors like heat or cosmic rays, or defects in manufacturing. These errors are probabilistic, which means you can't predict when exactly they're going to happen. The results of such errors depend on where they occur on the system, and range from having no effect, to corrupting your output, to causing your entire system to fail.

Mitigations for random errors are costly because there's no perfect way to remove them. While you can ensure manufacturing quality or keep your system cool, you can't shield your device against neutron rays—not even with layers of lead.

One of the most insidious things a neutron ray can do is "flipping bits" in your working RAM. Since modern computers contain so much RAM that take relatively little energy to "flip", this presents a large surface of vulnerability. ECC RAM was introduced to reduce the effects of bit-flips by storing additional bits of memory that can be used to detect and repair flipped bits within a word.

ECC RAM can only reduce but not eliminate these random errors: flip enough bits in a word and even ECC is powerless to correct them. There are also computing surfaces that are completely unprotected, such as L1 cache and registers. Luckily, these latches tend to take much more energy to flip, and so the number of cosmic particles that can flip them are relatively few.

So, tl;dr: Yes, there is an expected rate of error of computation. Some of them happen predictably because of design bugs, and others unpredictably because of random events.

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)

1

u/i_invented_the_ipod Nov 23 '15

Yes, there's an expected error rate, but it's vanishingly-small. Other than some safety-critical systems, and locations where maintenance is impossible (space, at the bottom of the ocean), people pretty much operate as if the rate is zero.

I couldn't find a published figure for modern processors, but as a back-of the envelope estimation, you can probably assume that the rate is much lower than 0.01 failure per year, per processor.

Memory failures are roughly that common, and are something that cluster computing systems take into consideration. I don't know of any cluster-computing systems that take processor failures (other than self-reported failures) into account, so they must be rarer than that.

1

u/yendrdd Nov 24 '15

In perfect conditions, I computer will do exactly what you tell it to. So those 100k Excel calculations will come out how you expect them to if you setup your algorithms correctly.

However, there is still the very, very, very small chance that a calculation will completely go out the window. And if it does, there's usually redundancy checks in place to prevent that error from totally screwing up your application.

The likelihood of you screwing up is greater than a computer that's in perfect working condition screwing up.

1

u/NewAnimal Nov 24 '15

it took me a minute to realize why you learn about mathematical induction in intro compsci math classes. given everything else is stable (hardware/algorithm,etc) your "loop" with 1 million loops should always work given your algorithm follows mathematical induction.

1

u/falafel_eater Nov 24 '15

A rule of thumb I've heard is that a typical processor will make one computation error per month, on average.
This is a major issue for systems consisting of tens of thousands of processors, because on average you encounter an error every few minutes.
Like people said, using ECC and saving parity/checksum data helps make a system much more fault tolerant.
Depending on your specific field and usage, this is either a non-issue or a hurdle that must be actively planned for.
For Excel spreadsheets, probably a non-issue.