« Avast, Ye Landlubbers | Main | Herbal Vi,agra 1337 »

June 02, 2004

Thirty Four, Plus or Minus Two

I have never really trusted Microsoft's built-in calculator, because it doesn't use a stack. Without a stack, it ends up ignoring the order of operations. Sometimes I forget this, and end up getting burned by the calculator's wrong answers. I was just ranting to someone in the lab about this, but they didn't believe me. Thus, I loaded up calculator, and typed in 2 + 10 * 3. Any good calculator would know that 10 * 3 takes priority over the 2 + ..., so the answer should be 32. At the time, I argued that the stupid Microsoft calculator wouldn't pay attention to the order of operations, and thus output (2 + 10) * 3, or 36. Lo, the calculator had to spite me and this is what it answered:

2 + 10 * 3 = 32


What?! Since when did Microsoft finally issue a patch to deal with this annoyance? It looked like I was wrong, and just didn't know how to use a calculator. But then the devious Computer Science TA part of me kicked in, and I tried the exact same operation after switching the calculator off "Scientific Mode." The answer? 56. That's because I really can't use a calculator. After typing 2 + 10 * 3 more carefully, I got this:

2 + 10 *3 = 36


Aha! I was right. The stupid Microsoft calculator does get things wrong, when not in scientific mode. In fact, this is worse than if it had also gotten the wrong answer both times. Whoever was in charge of programming the stupid thing actually had to do more work so that the calculator gives the wrong answer, since they had to implement both a stack-based and a stupid-based calculator in the same program. Stupid calculator programmers.
What sort of \'\'feature\'\' is this?!?

Posted by jim at June 2, 2004 03:30 PM

Comments

I enjoy a good rant more than the next person, but you're wrong here Jim. Scientific calculators have always had a stack, and behave like that. Other calculators, that look exactly like the bottom picture here, do not have a stack. There are two commonly used calculators out there in the real world, and it only makes sense that they'd include the more common, simpler, non-stack based calculator when making an operating system fro the common people. Just be glad they didn't also include RPN.

Posted by: Charlie at June 2, 2004 04:18 PM

mmmmm...RPN

Posted by: Anonymous at June 2, 2004 05:50 PM

Since when do scientists have their own order-of-evaluation? I remember learning * over + in a math class, and my daughter has just gone through the same material in 7th grade.

Don't mathematicians set these rules, and if not, what kind of mode is that calculator in when not in "scientific" mode? Is it "We don't know operator precedence" mode?

Posted by: rkc at June 2, 2004 07:14 PM

A non-scientific calculator, though, is not meant for the more complex operations. It doesn't implement order of operations because most people don't use their pocket calculators for that type of thing. They use it to figure out their grocery bills or something like that where it's more important what the result of the previous calculation was and would just be confusing if the number displayed didn't figure into the result. I'm with Charlie on this one.

Posted by: Chris Hill Festival at June 2, 2004 09:24 PM

Even non-scientific people should be aware of order of operations. Even if people are just using a cheapo calculator to figure out their grocery bill, they're not going to want to hit:


3 * 4.99
Memory Store
5 * 1.50
+
Memory Recal
Memory Store
etc.

Instead, they're going to type 3 * 4.99 + 5 * 1.50. There's a reason calculators, whether simple or complicated, have an "=" button. Even when I was in elementary school I knew enough to undestand that pressing "=" would flush the stack (well, I didn't know about stacks and whatnot, but I knew what the final effect was). My dearly departed TI-35 had a scientific mode toggle, and that did not turn on and off the stack. I'm going to have to agree with myself and Ron on this one, not Chris (everybody knows a Ph.D. trumps a Masters Degree)

Posted by: Jim at June 3, 2004 02:33 PM

Even if everybody should be aware of order of operations, there's a certain wisdom to providing people what they are used to and prefer. Everybody *should* be using Dvorak instead of Qwerty (if only for health reasons), but when building an OS for the general populace who would make Dvorak the only keyboard layout, or even the only keyboard layout?


The switch to a lesser used standard is doubly dangerous for calculators. A user that's accustomed to the standard desk calculator will be unaware that the calculator is rearranging operations behind his back, resulting in incorrect answers with no easy way to tell other than running things through in a more atomic manner.


Those who prefer a stack based calculator are going to be aware of the difference and much more likely to check for it.

Posted by: Charlie at June 5, 2004 04:23 PM

That makes me sad inside...

Posted by: The (not so) Phantom Reviewer at June 8, 2004 08:03 AM