2

Perhaps I'm just not understanding RPN correctly, but whenever I translate something like

2^2^3 then I get 22^3^

But if I try to execute that it's wrong! Because that will result in 64 (4^3), but what I need it to do is result in 256 (2^8)

How do I fix this?

MJD
  • 67,568
  • 43
  • 308
  • 617
Meshach
  • 217

1 Answers1

4

You need 2 2 3 ^ ^, because exponentiation is normally understood from right to left. That is, something like 2^2^3 means 2^(2^3), not (2^2)^3. So when you convert to RPN that's how you have to convert it.

Willemien
  • 6,730
MJD
  • 67,568
  • 43
  • 308
  • 617
  • 1
    RIGHT! Because the two rules are IF 1) operator precedence is greater OR 2) operator precedence is equal AND left associative THEN push. – Meshach Jan 23 '14 at 20:45