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?


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.

  • 1
    $\begingroup$ RIGHT! Because the two rules are IF 1) operator precedence is greater OR 2) operator precedence is equal AND left associative THEN push. $\endgroup$ – Meshach Jan 23 '14 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.