Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'HP 48GX emulator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
HP 48GX emulator
Authored by: babbage on Feb 25, '02 08:27:17PM
It's called 'postfix' math, and the HP calculator is a common teaching tool in introductory programming classes, because [a] it's a great way to reduce ambiguity in your notation, and [b] it's a great way to teach about stack based data structures. Consider:
  • "normal" infix math:
    3 * 4 / 5 = ???
    parentheses are needed to solve the problem, because there is more than one valid way to parse the equation.
  • postfix math:
    3 4 * 5 / = 12 5 / = 60
    or
    3 4 5 / * = 3 4/5 * = 2.4 [or 2 2/5]
    no ambiguity, and solving the problem is a simple series of repitions

The thing to notice is that you keep adding values to your 'stack' until you hit an operator, at which point you pop the top two items off the stack and apply the operator to those two items, placing the resulting value back on the stack, and you repeat this process until the stack is reduced to a single value. figuring out the strategy used by HP's calculators is a great way to learn about stack structures, and knowing how to work with stacks makes all kinds of programming problems easier (stacks describe the most recent web pages visited, the order you're allowed to use tags in valid HTML/XML documents, etc).

I hated that class but I'm glad I understand the material... ;)

[ Reply to This | # ]