Filed under: iPod Family, Bugs/Recalls, iPhone
Apple's tasty calculator mistake

This error can be demonstrated by entering Pi (3.141592654) manually, instead of using the Pi button -- you will get the correct answer each time. Therefore, this error only shows up when you use the Pi button.
So, be sure to read up on this bug from the tipsters website before you use the calculator for anything too important.
Update: Reader Vineet writes in the comments to note that he believes this behavior is typical of stack-based calculators and should be considered more of an operator-expectations issue than a true bug. Dr. Drang responds (with a little bit of attitude) to disagree, maintaining that the behavior is a legitimate bug.
Thanks for the tip, Dr. Drang!


![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 2 of 3)
Patrick said 11:11AM on 8-26-2008
It's probably a pretty simple bug... it can occasionally be difficult to avoid rounding down automatically, and it's easy to make mistakes.
Reply
Chris said 11:21AM on 8-26-2008
And that's why you should buy PCalc....
Reply
Xof said 11:46AM on 8-26-2008
Viva RPN!
Reply
Brad said 11:28AM on 8-26-2008
That's it, I'm done with all Apple products!
Reply
Mr Paul said 11:28AM on 8-26-2008
Cool, I didn't even know that scientific calculator was in there! And just the other day I was wishing it had a scientific mode....
Nifty bug. Nice miss by the testers too :)
Reply
Vineet Shah said 11:54AM on 8-26-2008
This isn't necessarily a bug. An inconvenience, maybe. But this is just how some calculators work. To use the pi button on the iPhone calculator, and several other low-level scientific calculators, the pi must be first on the screen, then the operator (+-*/), then the operand (2 in this case). Then add the 5.
These calculators, usually the ones that don't show the entire line of what you're typing, calculate values using stacks. You press a number, it puts it on the stack, press an operator (+-*/), it puts it on the stack. Then when you finally press the second number, it calculates the value using all 3 saved values. For values such as pi however, you are not actually putting it on the stack when you press it; you are simply displaying its value. Therefore, when typing 2 * pi + 5, notice that the highlighted * button does not go away when typing the pi; it does not take pi as a value you are multiplying. It is simply showing you the value of pi. Then, once you press the +, it thinks you have changed your mind, and now want to add something instead of multiply. So all that's left is the 2 + 5, giving you the answer of 7.
Another example of an inconvenience with the iPhone scientific calculator can be demonstrated by trying to find the sum 5 + sqrt(2).
On a proper scientific calculator, you can type the equation above, hit enter, and get the proper answer, approximately 6.414. On the iPhone however, you have to watch how you type it in; whenever you press a function button such as square root or sin/cos/tan, it will immediately perform the function with whatever value is on screen.
So first you will have to type the 2, then press the square root button on the iPhone, so that it will take the square root of the 2 (the value on the screen). Then you must add 5 by typing + 5.
Again, not a bug. Just a stack-based calculator. YOu are constantly performing operations with the values that are stored on the stack. Many, many calculators are like this. When you see a calculator that does not show the full line that you are typing, you can usually be sure that it computes values using stacks. Most calculators a decade ago were like this (from what I hear, I wasn't alive to see them), so it's really not as hard as it seems. Just something you get accustomed to. I guess taking Java in high school really does pay off.
Reply
Charlie said 2:31PM on 8-26-2008
I think your thinking of RPN (reverse polish notation ) which is what the HP calculators used a decade ago (which is the visual style apple is modeling).
Those are usually stack based operation where you would have to type "pi 2 + 5 x "
This a bug because if you just type "pi x 2 +" it will go to 6.283 ,
but if you type "2 x pi + " it will go to 2.
Yonzie said 4:24AM on 8-27-2008
Am I the only one who's noticed the x^3 bug?
enter '1000' (or more zeroes) and take the 3rd root (at the right of the sqrt button, then 3, then enter).
Then press the x^3 button.
http://gallery.me.com/jensvilstrup/100008/IMG_0005/web.jpg
Reply
Dragon said 5:04PM on 8-26-2008
I don't think thats a bug so much as rounding error, which you wouldn't see on most calculators. at least I've not seen many that show 15 decimal places.
Marcus said 12:49PM on 8-26-2008
My, you're a very eloquent ten year old, Vineet, I must say :-)
Reply
Vineet Shah said 1:10PM on 8-26-2008
My slip up, sorry. I meant two decades.
I'm 17. But thank you.
Marcus said 12:55PM on 8-26-2008
Yonzie, that's definitely to be expected. After all you're dealing with floats and probably something like Newtons method for finding the roots so you'll never get exact results.
Reply
Dr. Drang said 5:27PM on 8-26-2008
Vineet,
The second paragraph of your reply is a very good summary of the iPhone calculator's behavior--similar to, but a bit more detailed than, the description in my blog post.
I must, however, disagree with almost everything else you wrote. I have the advantage here of having used scientific calculators for almost twice as long as you've been alive, and I can assure you that *none* of them have worked the way you say is normal.
It is true that in "classic" calculators (those that display only the most recent number), trig, square, square root, and other functions act on the number you've just entered; so to get the square root of 2, you first enter 2, then push the sqrt button. Using your example, 5 + sqrt(2) would be entered:
5 + 2 sqrt =
That behavior is expected--even preferred--by old guys like me, and I would never think of it as a bug.
But the pi thing *is* a bug. No calculator I've owned (and I've had more calculators than you've had hot meals, sonny;) treats the pi key the way the iPhone does. Pressing the pi key is supposed to act just like I entered 3.1415926… manually, up to the significant digit limit of the calculator. That the iPhone's calculator doesn't act that way is simply wrong.
While I'm ranting, let me suggest that your use of the phrase "stack-based" is misleading to calculator aficionados, who would probably reserve that term for RPN calculators, like the classic HPs. The iPhone is definitely not an RPN calculator.
Reply
jsk said 4:51PM on 8-26-2008
Never trust the numbers ANY computer gives you.
The first problem with this discussion is that the "correct" answer is 11.28318530717959. It isn't. Its only, what, 11.28 or 11.3 (I forget which, it's been a while since I've done "real" math; but its a classic 1st year engineering school mistake - one our slide rule bearing ancestors would never have made). You're assigning way too much significance to all those extra digits. Or do we know for a fact that it really is 2.000000000000000 and 5.000000000000000 and not just 2 and 5?
Second, and far more importantly here, all digital computer have problems with floating point numbers. Its in their nature. They do binary integers and binary integers only. They have to do some mathematical trickery to do floating point numbers and bad things can happen when you fill up the register with ones and zeros (Is it a really large integer, or a really small decimal number, for example.). You get problems when programers get sloppy and don't account for these edge cases properly. Which is obviously the case here. (And why high end scientific calculator have special placeholders for numbers like pi, use algebra whenever possible instead of arithmetic, and save turning pi into a decimal approximation until the end, if ever.)
In short, you should never trust the numbers that any computer gives you. You should always ask yourself "is this the answer I was expecting?" And no, it doesn't matter if its a $200 hp rpn, an Excel spreadsheet, or especially, a throw away calculator app.
Oh, and the "stack" has nothing to do with it. If you're getting "7" when you calculate "2*pi+5", the calculator app is flat out dropping pi altogether, not changing the precedence of * over +.
Reply
Vineet Shah said 5:20PM on 8-26-2008
It's still the way it expects the user to enter in values. I agree that this isn't RPN, so it may not be directly stack-based, but similar to a stack-based calculator, it is picky about how you enter values, especially symbols such as pi. Another example is trying to find 2 + cos(30). The proper way to type it in is cos -> 30 -> + -> 2 -> =. Typing it any other way will not yield the proper answer, about 2.87, significant to 3 digits I believe for a trigonometric value. But nevertheless, in that way, it is very similar to RPN on the HP graphing calculators, since order matters. First the value, such as 30, then the function, such as cosine. Similarly, first any special digits such as pi, followed by an operator, then any operand. You will notice how the multiplication symbol stays highlighted until you enter a real second operand.
The best way to put this is is that by pressing pi, it is just showing you its value, a property of many calculators. To actually use this value, it must be entered first, OR you must press the equal sign. Again, notice how until you press the equal sign in 2*pi=+5, the multiplication sign will stay highlighted. Until you press the equal sign, the value of 2 * pi will not be entered on the stack; the only number on the stack will be 2 and the operation will be incomplete. To perform the operation, the = sign must be pressed.
Reply
Vineet Shah said 5:49PM on 8-26-2008
You've got me convinced. Misjudgment on my part. I do believe that after pressing the + sign in 2*pi+5, the value of 2*pi should be calculated. I guess I'm just naturally used to pressing the = sign after using symbols like pi, especially after seeing the * button still highlighted. Seeing the button highlighted was the main reason I never came across this bug, since I always pressed = to complete the calculation.
And yes, it's definitely not a postfix notation calculator, but all "classic" calculators behave in such a way that only one value is stored in memory, and newer calculations will replace that value in memory. "Stack-based" was not the correct term for this.
Reply
Dr. Drang said 6:45PM on 8-26-2008
A remarkably mature response. I hope you didn't take offense to my joking references to your relative youth.
Joe said 9:03PM on 8-26-2008
'"1 + 1" it could manage ("2"), and "1 + 2" ("3") and "2 + 2" ("4") or "tan 74" ("3.4874145"), but anything above "4" it represented merely as "A Suffusion of Yellow".'
http://www.thateden.co.uk/dirk/
Reply
germ said 10:49PM on 8-26-2008
Apple, give us a proper scientific calculator, that is, an RPN calculator, please!
Reply
Daniel said 10:03AM on 8-27-2008
I must have the most awesomest iPhone ever cause it works fine for me. I did 3.141592654x2+5 and got the same 11.283185308 answer. Then I did 2x3.141592654+5 and I got 11.283185308 again. I guess if I entered mure numbers for pie then I'd have gotten the bug but with the instructions TUAW is giving it works fine for me.
Reply