10.15.2009

iPhone/iPod touch calculator bug

I generally expect my computing devices to give me correct answers, or at least close answers to arithmetic questions. However, the calculator on the iPhone/iPod touch has a serious bug which renders it mostly useless for calculations involving large numbers.

Recently, I attempted to do some calculations on my iPod touch (specifically, calculating "100 choose 50" to test a combinatorial identity), when I ran across this strange bug.

If you have an iPhone or iPod touch, you can play along. Square brackets [] denote keys on the iPhone's Calculator app. Let me know if the bug shows up on your device.

Fire up the Calculator app, which comes with all of the recent iPhone OS versions. Put the device in landscape view to activate the scientific calculator, then punch in [1][EE][6][0][+/-][=][1/x]. This calculates the reciprocal of 10-60, which ought to be 1060. However, Calculator says that the answer is "1e+22", or about 38 orders of magnitude off! If you press [1/x] a few more times, you'll see that it gives the correct answer.



The strange behaviour doesn't stop there. Calculating the reciprocal of 10-38 gives 1 ([1][EE][3][8][+/-][=][1/x]) instead of 1038, and the reciprocal of 10-32 ([1][EE][3][2][+/-][=][1/x]) is "1.1111...e+32", which, while not off by orders of magnitude, is still grossly incorrect.

But it's not just the reciprocal key that is broken. Calculating, for example, 1080 divided by 1020 gives 1060 as expected ([1][EE][8][0][=][÷][1][EE][2][0][=]), but 1090 divided by 1030 gives 1022 ([1][EE][9][0][=][÷][1][EE][3][0][=]).

There's even more strangeness with large numbers. If you try to enter 10120 ([1][EE][1][2][0][=]), it works fine (though certain divisions involving this number may fail badly). However, you can't enter 10150 ([1][EE][1][5][0][=]); you'll get an error.

Here's the odd part: type in [1][0][0][x!], and the number that comes up is 9.33262...e+157, which is rather larger than 10150, and yet the calculator seems to have no trouble with it (the answer is correct, as Google Calculator tells me).


As of yet, I still haven't figured out what sort of strange coding was required to make this fail. Judging from the fact that 38 seems to play a fairly central role in the division bug (since results that should ordinarily come out to a large power of 10 will come out 38 or 76 orders of magnitude short), I'd say that the problem lies in the division algorithm that is being employed. Nevertheless, I'm having trouble believing that this sort of bug managed to slip past Apple's radar into a shipping product.

I've tested this on my iPod touch 1st Gen, a few iPod touch 2nd Gen and 3rd Gen devices, and a few iPhones (both 3G and original), and it doesn't appear in third-party calculators like Gabor Nagy's excellent Graphing Calculator, so it is likely a software glitch rather than a hardware problem.

Comments? Questions? Post away! I'd especially like to hear from people who are using older versions of the iPhone OS, to see if this is a recent bug or one which has been present for a while.