RPN Calculators

Thread Starter

Futurist

Joined Apr 8, 2025
792
RPN takes some getting used to, but after an amazingly short time it becomes very natural. You can do quite complicated calculations and do the conversion from infix (the way we normally write expressions, complete with all the parens) to postfix (which is what RPN is) in your head as you proceed.

My first intro to RPN was a Physics I test my freshman year in college. I had two Sharp scientific calculators and the batteries were dead in my normal one and I didn't have time to walk down to the drugstore to get more, so I went to get my backup and it's display was completely black from having been set on the dash of my car on a hot day. So my roommate loaned me his HC-41CV and gave me a brief tutorial on how to use it. When the prof was handing out the exam, I told him that this was my first time using an HP calculator, to which we replied, "We'll take that into account." It was a good thing, I got a 96% on the exam even though I didn't get a single numerically correct answer on the entire exam! But since I had set everything up correctly and it was just the evaluation of the final expression, the penalty was low, especially since I included ROM (rough order of magnitude) estimates for each answer.
Yet I bet few here would advocate an RPN notation in a programming language, very easy to do and parse etc, but I bet most programmers would hate it. But it might be an interesting exercise in programming language grammar, be able to accept either RPN or standard notation, not hard to define a parser that can distinguish.
 

crutschow

Joined Mar 14, 2008
38,543
Yet I bet few here would advocate an RPN notation in a programming language, very easy to do and parse etc, but I bet most programmers would hate it. But it might be an interesting exercise in programming language grammar, be able to accept either RPN or standard notation, not hard to define a parser that can distinguish.
The old Forth language (among others) used postfix notation.
 

joeyd999

Joined Jun 6, 2011
6,337
Yet I bet few here would advocate an RPN notation in a programming language, very easy to do and parse etc, but I bet most programmers would hate it.
Some of us do use it because it is easy.

PIC18F Assembly:
;***********************************************
;** COMPALT -- Compute Alternate Coefficients **
;***********************************************

compalt
    recall  1       ;B                     -> 0
    call    pushcp  ;B                     -> 1
    call    pushcp  ;B                     -> 2
    call    mulf    ;B^2                   -> 1
    pushfpc f4      ;4                     -> 2
    recall  2       ;A                     -> 3
    call    mulf    ;4*A                   -> 2
    recall  0       ;C                     -> 3
    call    mulf    ;4*A*C                 -> 2
    call    subf    ;b^2-4AC               -> 1
    call    log2f   ;log2(B^2-4AC)         -> 1
    pushfpc f2      ;2                     -> 2
    call    divf    ;log2(B^2-4AC)/2       -> 1
    call    exp2f   ;sqrt(B^2-4AC)         -> 1
    peeksto 3       ;save 'E' coeff
    call    addf    ;B+sqrt(b^2-4AC)       -> 0
    pushfpc fm2     ;-2.0                  -> 1
    recall  2       ;A                     -> 2
    call    mulf    ;-2A                   -> 1
    call    divf    ;(B+sqrt(B^2-4AC))/(-2A) -> 0
    popsto  4       ;save 'F' coeff

    return
 
Last edited:

Thread Starter

Futurist

Joined Apr 8, 2025
792
Some of us do use it because it is easy.

PIC18F Assembly:
;***********************************************
;** COMPALT -- Compute Alternate Coefficients **
;***********************************************

compalt
    recall  1       ;B                     -> 0
    call    pushcp  ;B                     -> 1
    call    pushcp  ;B                     -> 2
    call    mulf    ;B^2                   -> 1
    pushfpc f4      ;4                     -> 2
    recall  2       ;A                     -> 3
    call    mulf    ;4*A                   -> 2
    recall  0       ;C                     -> 3
    call    mulf    ;4*A*C                 -> 2
    call    subf    ;b^2-4AC               -> 1
    call    log2f   ;log2(B^2-4AC)         -> 1
    pushfpc f2      ;2                     -> 2
    call    divf    ;log2(B^2-4AC)/2       -> 1
    call    exp2f   ;sqrt(B^2-4AC)         -> 1
    peeksto 3       ;save 'E' coeff
    call    addf    ;B+sqrt(b^2-4AC)       -> 0
    pushfpc fm2     ;-2.0                  -> 1
    recall  2       ;A                     -> 2
    call    mulf    ;-2A                   -> 1
    call    divf    ;B+sqrt(B^2-4AC)/(-2A) -> 0
    popsto  4       ;save 'F' coeff

    return
I agree it isn't "hard". The entire root is our tradition of operator precedence, lose that and everything simplifies. Of course we'd need parentheses if we wanted to override a (say) left to right evaluation order, so there'd still be a place for RPN.
 
Top