Computers might struggle to exhibit intelligent behaviour, but blindly performing arithmetic calculations is surely their forte. Or is it?
The failure of Google's online calculator and Excel's apparent inability to give correct answers to simple calculations are both well-known problems among programmers, but these aren't really bugs in the normal sense of the word. Instead they're just a consequence of the fact that computers suck at maths.
Computers perform calculations in quite a different way from the methods that humans use to do arithmetic β and that means that they habitually come up with the wrong answer. Here we investigate some of the shocking consequences of this revelation before delving into the reason why computers suck at maths.
Close isn't close enough
For anyone still to be convinced that computers can't get simple arithmetic right, let's start off with a few examples that you can try out yourself.
First up, Google's calculator. If you've never tried it out before, to get a feel for how it works, surf to www.google.co.uk, type 5*9+(sqrt 9)^3 into the search box and click on 'Search'. You'll find that it comes back with the correct answer: '5 * 9 + (sqrt 9) ^3 = 72'.
Now let's try another calculation. Type in 599,999,999,999,999 - 599,999,999,999,998. Quite clearly, this should give an answer of 1. Unbelievably, however, Google responds with this: '599,999,999,999,999 β 599,999,999,999,998 = 0'. Just a rare and unfortunate example, perhaps?
OK then, let's try another simple calculation. Type =850*77.1 into cell A1 of an Excel 2007 workbook (it doesn't work β or should that be it does work β in earlier versions of Excel). A bit of mental arithmetic suggests that the answer ought to be in the region of 60,000; in fact the correct answer is 65,535.
Excel has other ideas. It will tell you that the result of this multiplication is 100,000, which is out by a massive 34,465. And to prove that this is no flash in the pan, how about using a selection of online calculators to work out 1.0 - 0.9 - 0.1?
You'll probably find at least half of them will come up with an answer of -2.77555756 E-17 β scientific notation for -0.0000000000000000277555756. (If all the ones you try give the right answer, take a look at www.calculator.net.)

BAD MATHS: Since 1.0 - 0.9 - 0.1 equals 0, why are so many online calculators convinced that this value is the answer instead?
OK, this answer might not be far removed from the correct answer of 0, but why can't the calculator come up with the right answer β an answer that's blatantly obvious to anyone who is conversant with simple arithmetic?
How computers do maths
Although computers can handle integers (whole numbers), for general-purpose arithmetic they store numbers in floating point format because it's so much more efficient in memory use.
Let's take the double precision floating point representation as an example. It uses 64 bits to store each number and permits values from about -10308 to 10308 (minus and plus 1 followed by 308 zeros, respectively) to be stored. Furthermore, fractional values as small as plus or minus 10-308 (that's a decimal point followed by 307 zeros and then a 1) can be stored.
By way of contrast, if the same 64 bits were used to store integers, the range would be β9,223,372,036,854,775,808 to +9,223,372,036,854,775,807, and fractional values couldn't be represented.
The secret to this apparently amazing efficiency is approximation. Of those 64 bits, one represents the sign (so whether the value is positive or negative), 52 bits represent the mantissa (that's the actual numbers) and the remaining 11 bits represent the exponent (how many zeros there are or where the decimal point is).
So although a much greater range of numbers can be stored using floating point notation, the precision is actually less than can be achieved in integer format, since only 52 bits are available. In fact, 52 bits of binary information represents a 16-bit decimal number, so any values that differ only in their 17th decimal point will actually be seen as identical.
The situation with Google thinking that 599,999,999,999,999 - 599,999,999,999,998 equals 0 is similar, although it's evident that Google's calculator actually uses less than the normal 52 bits for the mantissa. That some calculators give a non-zero result to the calculation 1.0 - 0.9 - 0.1 might seem different since we appear to be nowhere close to the limit of 64-bit floating point arithmetic.
But that's forgetting one important fact β that computers work in binary. And although 0.1 might have only one significant digit in decimal, in binary notation the mantissa is a repeating sequence. This means that 0.1 can never be represented accurately in binary, no matter how many bits you use.





Your comments (28) Click to add a new comment
pete_l
November 7th
28. > but these aren't really bugs in the normal sense of the word
Err, no. I think you'll find these really are bugs. However if you think computers suck at maths, just find any passer-by in the street and give them the same problems to solve. That's what sucking at maths is really like.
Alert a moderator
robl
November 6th
27. I read statements like this so many times and now longer believe them. Not taking onyones "word for it" I did indeed type =850*77.1 into Excel, Excel 2007 SP2 to be exact. The answer it came back with was?
65535.
Spot on!
Try it yourself.
Alert a moderator
graygaffer
November 4th
26. mrabarnett - not quite. They upgraded the CPU from 16 bit to 32 bit but the old attitude control module truncated its internal computations to 16 bit. So when the sensor reading went over 65535 the control code thought the rocket was pointing somewhere else and responded accordingly.
Upgrading bit width is a tricky issue especially when this kind of code tends to be written in assembler. A mechanical conversion approach typed the internal arithmetic as short for syntactic reasons on the assumption that it used to maniputlate short variables so keep it that way, but the semantics of the API matching fell through the cracks.
Alert a moderator
innmorris
November 2nd
25. ecdinovo, are you saying the IBM POWER6 overcomes the physical limitations of floating point numerical storage in a binary system by not storing information in standard 64 or 128 bit floating point format but as an infinite string of binary coded decimal digits? Are you also saying that due to the hardware accelerators, it can take an infinite BCD representation of a floating point number and multiply it by another infinite BCD representation of a floating point number in fractions of a second with no error? Impressive, especially since the values involved are infinite.
Alert a moderator
ecdinovo
November 2nd
24. Duh, ever heard of base 2? That's why you need a processor that conforms to a decimal arithmetic standard, like IBM's POWER 6:
"only POWER6 systems have two integrated hardware accelerators designed to enhance performance: Decimal Floating-Point for business applications [...]"
They're very popular in the financial world because of that.
Alert a moderator
mrabarnett
November 2nd
23. The reason why the overflow occurred in Ariane V's software was that they decided to use the same software that they'd used for Ariane IV, on the very sensible basis that it was tried and tested.
Unfortunately, they failed to consider that the new rocket's engines were more powerful...
Alert a moderator
Tell us what you think
You need to Log in or register to post comments