RPN Handheld Calculator

An HP-15C Voyager series inspired RPN calculator, built with SDL2. Designed for handheld devices with gamepad input, with full support for desktop keyboards.

Features

  • Reverse Polish Notation (RPN): Efficient, stack-based calculations.
  • Full Complex Number Support: All arithmetic and transcendental functions work with complex numbers.
  • Comprehensive Math Library: Includes standard arithmetic, trigonometry, logarithms, exponential functions, and absolute value.
  • Statistical Functions: Mean, sample standard deviation, linear regression, and correlation coefficient for one or two variables.
  • Number Theory & RNG: Integer part, fractional part, and a random number generator.
  • Combinatorics: Permutations (Py,x) and combinations (Cy,x).
  • Stack Manipulation: Full control with ENTER, DROP, SWAP, ROLL, LSTx, etc.
  • Keystroke Programming:
    • Store up to 100 programs (labels 00-99).
    • Full program editing (insert, delete, overwrite).
    • Branching (GTO), subroutines (GSB, RTN), and conditionals.
    • 10 user flags for advanced program logic.
  • 100 Memory Registers: Store and recall values from registers 00-99.
  • Cross-Platform: Runs on any system supported by SDL2.
  • Persistent Programs: Programs are automatically saved on exit and loaded on start.

Controls

  • D-Pad: Navigate the on-screen keyboard.
  • ‘A’ Button: “Press” the selected on-screen key.
  • Start : Main ENTER key.
  • B: <- (Backspace/Delete)
  • L1: f-shift (blue keys)
  • R1: g-shift (gold keys)
  • Program Up/Down: The dedicated and keys on the virtual keyboard are used for navigating program steps during editing.
  • Statistics Keys (using ∑+ key):
    • ∑+: Base key, adds a data pair (x,y) from the complex number x+yi in the X register.
    • ∑-: f-shift of ∑+, removes a data pair using the same method.
    • CL∑: g-shift of ∑+, clears all statistics registers.
    • μ (Mean): g-shift of √x. Returns mean_x + i*mean_y in X.
    • σ (stdev): g-shift of LOG. Returns s_x + i*s_y in X.
    • L.R. (Linear Regression): g-shift of .
    • r (Correlation): g-shift of 1/x.
  • Hyperbolic Key (HYP): g-shift of CHS.

Download and Install here:
RPN_v0.2.muxapp (27.5 KB)

Changelog:

  • v0.2: Solver improvement and bug fixing
4 Likes

RPN Calculator User Manual

Welcome to the RPN Calculator! This guide will walk you through its features, from basic arithmetic to advanced programming. This calculator is inspired by the legendary HP-15C and uses Reverse Polish Notation (RPN) for fast and efficient calculations.

Please note: long content ahead

The Basics: RPN and the Stack

Instead of typing 2 + 3 =, RPN calculators use a “stack” to hold numbers. You place numbers onto the stack and then apply operations to them.

The stack has four levels, which you can see on the display:

  • X: The bottom level. This is your main entry and result line.
  • Y: The second level.
  • Z: The third level.
  • T: The top level.

To calculate (2 + 3) * 4, you would perform these steps:

  1. 2, ENTER - Pushes 2 into the X register.
  2. 3 - The stack “lifts,” moving 2 to the Y register. 3 is now in X.
  3. + - The calculator adds the X and Y registers (3 + 2), and the result, 5, is placed in X.
  4. 4 - The stack lifts, moving 5 to Y. 4 is now in X.
  5. * - The calculator multiplies X and Y (4 * 5), and the result, 20, is placed in X.

This method is very efficient and removes the need for parentheses.

The Display and Keyboard

The Display (LCD)

The LCD is divided into 5 lines.

  • Status Line (Top): The top line is a dedicated status display.
    • On the left, it shows mode indicators like f, g, HYP, and the current program label (e.g., PRGM 01).
    • In the center, it displays the current time.
    • On the right, it shows a battery level icon.
  • Stack (Lines 2-5): The lower four lines show the T, Z, Y, and X registers of the RPN stack.

The Keyboard

  • Navigation: Use the D-Pad to move the selection cursor around the on-screen keyboard.
  • Pressing a Key: Use the ‘A’ button to “press” the currently selected key.
  • Shift Keys:
    • L1: Activates the “f-shift” (blue labels on keys).
    • R1: Activates the “g-shift” (gold labels on keys).
  • Common Shortcuts:
    • Start: The main ENTER key.
    • B: The <- (backspace) key.
  • Program Navigation:
    • key: Moves the cursor UP when editing a program.
    • key: Moves the cursor DOWN when editing a program.

Error Messages

If you perform an invalid operation (like dividing by zero), an error message (e.g., DIV BY ZERO) will appear on the display.

  • The error message will remain on screen until you press any key.
  • The operation that caused the error is cancelled, and the stack is not changed. This allows you to correct your input without losing your work.
Core Functions

Number Entry

  • 0-9: Standard number entry. The 0 key’s f-shift is π.
  • .: Enters a decimal point. If a decimal point has already been entered for the current number, this key acts as EEX (Enter Exponent) to begin scientific notation entry. Its f-shift is SCI and g-shift is FIX for setting display modes.
  • CHS: Change Sign. Flips the sign of the number in the X register or the number currently being typed.
  • <-: Backspace. Deletes the last digit typed.
  • CLx: Clear X. Sets the X register to 0. If you are typing a number, it clears the input buffer.
  • CLR: Clear Registers (f-shift of CLx). Clears all 100 memory registers (00-99).
  • CLA: Clear All (g-shift of CLx). Resets the entire calculator to its default state, clearing the stack, memory, statistics, and all programs currently in memory. It does not delete the programs.rpn save file.

Display Modes

You can control how numbers are displayed on the screen.

  • SCI: (f-shift of .) Sets scientific notation display. Press SCI, then a digit 0-9 for the number of significant figures.
  • FIX: (g-shift of .) Sets fixed decimal place display. Press FIX, then a digit 0-9 for the number of decimal places.
  • To return to the default floating-point display, press SCI or FIX, then ..

Stack Manipulation

  • ENTER: Pushes the value from X up to the Y register. This is how you separate numbers.
  • SWAP: Swaps the values in the X and Y registers.
  • ROLL: “Rolls” the stack down. T->Z, Z->Y, Y->X, and X->T.
  • DROP: Drops the value in X. The stack moves down to fill the space.
  • LSTx: Last X. Pushes the stack up and recalls the value that was in the X register before the last operation into X.

Memory Registers

You have 100 memory registers (00-99) to store values.

  • STO: Store. Press STO, then a two-digit number (e.g., 0, 1) to store the value from X into register 01.
  • RCL: Recall. Press RCL, then a two-digit number (e.g., 0, 1) to recall the value from register 01 into the X register.
Mathematical Functions

Arithmetic and Powers

  • +, -, *, /: Standard four arithmetic functions.
  • π: Pushes the value of π onto the stack (f-shift of 0).
  • : Raises the number in Y to the power of the number in X.
  • √x: Square root of the number in X.
  • : Squares the number in X (f-shift of √x).
  • !: Factorial (f-shift of *). Calculates the factorial of a non-negative integer in X.
  • 1/x: Calculates the reciprocal of the number in X.
  • ABS: Absolute Value (f-shift of CHS). Calculates the magnitude of a number. For a complex number a+bi, it returns sqrt(a²+b²).
  • Cy,x: Combinations (f-shift of +). Calculates the number of ways to choose x items from a set of y items.
  • Py,x: Permutations (g-shift of +). Calculates the number of ways to arrange x items from a set of y items.
  • RAND#: Random Number (g-shift of ENTER). Pushes the stack up and places a random number between 0.0 and 1.0 in the X register.
  • INT: Integer Part (g-shift of /). Replaces the number in X with its integer part (truncating towards negative infinity, like floor()). This works on both the real and imaginary parts of a complex number.
  • FRAC: Fractional Part (f-shift of /). Replaces the number in X with its fractional part. This works on both the real and imaginary parts of a complex number.

Trigonometry

  • Angle Modes: Use DEG, RAD, or GRD (f-shifts on 7, 8, 9) to set the angle mode.
  • SIN, COS, TAN: Standard trigonometric functions.
  • ASIN, ACOS, ATAN: Inverse trigonometric functions (f-shifts).
  • HYP: A modifier key (g-shift of CHS). Press it before a trig key to get its hyperbolic version (e.g., HYP then SIN gives SINH).

Solver, Integrator, and Derivative

The calculator can find roots, calculate definite integrals, and find the derivative of a function f(x) that you define as a program. These functions only operate on the real part of numbers.

  • SOLVE: Finds a root of a function.
  • INTEG: (f-shift of SOLVE) Calculates the definite integral.
  • DERIV: (g-shift of SOLVE) Calculates the numerical derivative.

Workflow:

  1. Write a Program: Create a program (e.g., at LBL 01) that takes a value from the X register, calculates f(x), and leaves the result in the X register.
  2. Set up Inputs:
    • For SOLVE: Put two initial guesses for the root in the Y and X registers.
    • For INTEG: Put the lower limit of integration in Y and the upper limit in X.
    • For DERIV: Put the point at which to find the derivative in X. The calculator will automatically refine its step size to find a stable result.
  3. Execute:
    • Press SOLVE (or its shifted version).
    • Enter the two-digit label of your program (e.g., 0, 1).
    • The calculator will compute and leave the result on the stack.

Example: Find the root of f(x) = x² - 9

  1. Program (LBL 01): P/R, 0, 1, , 9, -, P/R
  2. Run: 1, 0 (Initial guess in X), SOLVE, 0, 1
  3. Result: The X register will show 3.0.

Logarithms

  • LOG / 10^x: Base-10 logarithm and its inverse.
  • LN / e^x: Natural logarithm and its inverse.

Complex Numbers

This calculator has full support for complex numbers. Most functions will work with them automatically.
The i key has two primary functions for creating complex numbers:

  • To create a+bi: Enter a, press ENTER, enter b, then press i. This combines the number in the Y register (a) with the number in the X register (b) into a single complex number.
  • To create x+i: Enter a number x, press ENTER. With x in the X register, press i. This adds an imaginary component of 1 to the number.
  • Re / Im: (f/g-shifts on i) Extract the Real or Imaginary part of a complex number.

Example: Calculate sqrt(3 + 4i)

  1. 3, ENTER
  2. 4, i (Display shows 3+4i)
  3. SQRT (Display shows 2+i)

Example: Verify Euler’s Identity (e^(iπ) + 1 = 0)

  1. 0, ENTER
  2. π
  3. i (Creates 0 + i*π on the stack)
  4. e^x (Calculates e^(iπ), result is -1)
  5. 1
  6. +
  7. Result: The display will show 0.
Statistical Functions

The calculator can perform two-variable statistical analysis.

  1. Clear Data: Before starting, press CLSUM (g-shift of SUM+) to clear the statistics registers.
  2. Enter Data: To add a data pair (x, y), create a complex number x+yi in the X register and press ∑+. The easiest way to do this is to enter x, press ENTER, enter y, then press i. After pressing ∑+, the display will show the new count of data points (n).
  3. Remove Data: To remove a data pair, create the same x+yi complex number and press ∑- (f-shift of ∑+).
  4. Calculate:
    • μ (Mean) (g-shift of √x): Calculates the mean. The result is placed in the X register as a complex number x̄ + i*ȳ.
    • σ (stdev) (g-shift of LOG): Calculates the sample standard deviation. The result is placed in the X register as a complex number s_x + i*s_y.
    • L.R. (g-shift of ): Performs a linear regression. The y-intercept is placed in the Y register, and the slope of the best-fit line is in the X register.
    • r (g-shift of 1/x): Calculates the Pearson correlation coefficient, which measures the linear correlation between x and y. The result is placed in the X register.

Example: Find the mean, slope, and intercept for the data points (4, 10) and (6, 20).

  1. CL∑
  2. 4, ENTER, 1, 0, i, ∑+ (Display shows 1)
  3. 6, ENTER, 2, 0, i, ∑+ (Display shows 2)
  4. μ
    • X register will show 5+15i.
  5. L.R.
    • X register (slope) will show 5.
    • Y register (y-intercept) will show -10.
Programming the Calculator

You can automate almost any task by recording your keystrokes into one of 100 programs (labeled 00-99).

Basic Workflow

  1. Enter Program Mode: Press P/R (f-shift of R/S), then enter a two-digit label (e.g., 0, 1).
  2. Record Keystrokes: Simply press the keys you want in your program. They will be recorded step-by-step.
  3. Exit Program Mode: Press P/R again.
  4. Run Program: Press R/S, then enter the two-digit label of the program you want to run.

Example: Area of a Circle (πr²)

This program takes a radius from the X register and calculates its area.

  1. Program:
    • P/R, 0, 1 (Enter program mode for label 01)
    • π
    • *
    • P/R (Exit program mode)
  2. Run:
    • 5, ENTER (Put the radius, 5, on the stack)
    • R/S, 0, 1 (Run the program)
  3. Result: The display will show 78.5398.

Program Control

The programming system includes instructions for controlling the flow of execution.

  • Branching and Subroutines: Use GTO to jump to another program label, or GSB to call a subroutine which can return with RTN.
  • Conditionals: Instructions like x>0? or x=y? can be used to skip the next instruction if a condition is not met.
  • Flags: The calculator has 10 flags (0-9) for storing simple state. Use SF 1 to set flag 1, CF 1 to clear it, and F? 1 to test it.

Happy calculating!

1 Like

RPN Calculator Programming Guide

This calculator supports keystroke programming, allowing you to store and automate complex sequences of operations. This guide explains how to create, edit, and run programs.

Basic Concepts
  • Keystroke Programming: You “record” a sequence of key presses into a program memory slot. When you run the program, the calculator executes those key presses automatically.
  • Labels: Programs are stored under numeric labels from 00 to 99. This allows you to have up to 100 different programs.
  • Program Counter (PC): This is a pointer to the current step in a program. When editing, it shows where the next instruction will be recorded. When running, it points to the instruction being executed.
Creating and Editing Programs

Entering and Exiting Program Mode

The P/R key (f-shift R/S) is the master key for programming.

  • To Create or Edit a Program:

    1. Press P/R. The display will prompt PRGM LBL __.
    2. Enter the two-digit label (00-99) of the program you want to work on.
      • If the label already contains a program, it will be opened for editing, with the cursor at the first step. The existing program is not cleared.
      • If the label is empty, you will start a new, blank program at that label.
  • To Find the Next Available Program Slot:

    1. Press P/R.
    2. Instead of entering a label, press ENTER.
    3. The calculator will automatically find the first empty label and start a new program there. If all labels are full, a message will be displayed.
  • To Exit Program Mode:

    • Press P/R again. You will return to Normal Mode.

Recording and Editing Instructions

Recording and Editing Instructions

Once in program mode, the display changes to show the program listing.

  • Recording: Simply press the keys you want to record. Each key press is added as a step, and the program counter (>) advances automatically.
  • Navigating: Use the dedicated and keys on the virtual keyboard to move the program counter without recording new steps. This allows you to view or edit your program.
  • Overwriting: To change an instruction, navigate to it using / and press the new key you want. The old instruction will be replaced.
  • Deleting: Navigate to the instruction you want to remove and press <- (Backspace). Subsequent instructions will shift up.
  • Clearing a Program: While in program mode, press CLA to delete all instructions in the current program.
  • Inserting: Navigate to the position where you want to insert a new step and press <+ (f-shift <-). This inserts a blank line and shifts subsequent instructions down. You can then enter the new instruction on the blank line.
Running Programs

The R/S key is used to run programs and to pause/resume them.

  • To Run a Program by Label:

    1. Press R/S. The display will prompt RUN LBL __.
    2. Enter the two-digit label of the program you want to run.
    3. The program will begin executing immediately.
  • To Re-run the Last Program:

    • Press R/S twice. This is a convenient shortcut to execute the most recently run program again without re-entering its label.
Program Control Instructions

You can use special instructions within your programs to control their flow.

Pause and Resume (R/S)

Placing an R/S instruction in your program will cause it to pause execution at that point. This is useful for programs that need to stop for user input. To resume the program from where it paused, simply press R/S again.

Note: A program automatically stops at its last instruction, leaving the result on the stack. An R/S at the very end is not necessary unless you want to explicitly show a “PAUSED” state.

Unconditional Branching (GTO)

The GTO (Go To) instruction causes the program to jump to a different label and continue execution from there.

  • Usage: GTO, 0, 1 will jump to the beginning of the program at LBL 01.

Subroutines (GSB and RTN)

  • GSB (Go to Subroutine) works like GTO, but it remembers where it came from.
  • RTN (Return) tells the program to go back to the instruction right after the GSB call that sent it to the subroutine. This is essential for creating reusable pieces of code.

Conditional Skips

Conditional instructions test the value in the X register (or X and Y registers).

  • If the condition is true: The very next instruction is executed.
  • If the condition is false: The very next instruction is skipped.

Note: These conditional tests are non-destructive. They check the values in the X and Y registers without changing them or dropping the stack.

Available conditions include: x>0?, x=0?, x!=0?, x<=y?, x=y?, x!=y?.

Flags (SF, CF, F?)

The calculator has 10 flags (0-9) that you can turn on or off to store simple yes/no state.

  • SF (Set Flag): SF, 1 turns Flag 1 ON.
  • CF (Clear Flag): CF, 1 turns Flag 1 OFF.
  • F? (Test Flag): F?, 1 checks if Flag 1 is ON. If it is, the next instruction runs. If it’s OFF, the next instruction is skipped.

Using Programs with SOLVE, INTEG, DERIV

The SOLVE, INTEG (Integrate), and DERIV (Derivative) functions all operate on user-written programs. This is one of the most powerful features of the calculator.

When you use one of these functions, you provide the label of a program that defines your mathematical function, f(x). The calculator then calls your program repeatedly to find the solution.

Your program’s responsibility is simple:

  1. It should assume the input value, x, is in the X register when it starts.
  2. It should perform its calculations on the real part of the number. The solver, integrator, and derivative functions do not support complex numbers.
  3. It must leave the final result, f(x), in the X register before it ends (with RTN or by reaching the last step).

The program should not consume extra items from the stack, as the solver does not provide them. It should only use the initial value in X.

Example: A program to calculate f(x) = x³ - 2x + 5 for the solver would look like this:

Program (LBL 20):

  1. STO 00 (Store x)
  2. RCL 00
  3. * (x³)
  4. 2
  5. RCL 00
  6. * (2x)
  7. - (x³ - 2x)
  8. 5
  9. + (x³ - 2x + 5)
  10. RTN
Saving and Loading

Your programs are automatically saved to a file named programs.rpn when you exit the calculator application. They are automatically loaded the next time you start it, so your work is always preserved.

Programming Examples

Example 1: Area of a Circle

This program will take a radius from the stack, calculate the area (π * r²), and pause to display the result.

Program (LBL 01):

  1. Enter Program Mode: P/R, ENTER (or 0, 1 if it’s the first program)
  2. Record the steps: , π, *
  3. Exit Program Mode: P/R

To Run:

  1. Enter the radius: 5, ENTER
  2. Run the program: R/S, 0, 1
  3. Result: The program will end with the area, 78.5398, in the X register.
Example 2: Sum of Integers from 1 to N

This program calculates the sum of all integers from 1 up to a number N provided on the stack. It demonstrates a loop using GSB and GTO.

Program (LBL 10 - Main Routine):

  1. Enter Program Mode: P/R, 1, 0
  2. Record the steps:
    • 0 (Initialize sum in X, pushes N to Y)
    • SWAP (Put counter N in X, sum in Y)
    • GSB, 1, 1 (Call the loop in LBL 11)
  3. Exit Program Mode: P/R

Program (LBL 11 - Loop):

  1. Enter Program Mode: P/R, 1, 1
  2. Record the steps:
    • STO 00 (Temporarily store counter N)
    • + (Add counter to the running sum)
    • RCL 00 (Recall counter)
    • 1, - (Decrement counter)
    • x>0? (Is the counter still > 0?)
    • GTO, 1, 1 (If yes, loop again)
    • DROP (Drop the final counter (0) from X)
    • RTN (Return, leaving sum in X)
  3. Exit Program Mode: P/R

To Run:

  1. Enter the number N: 10, ENTER
  2. Run the main routine: R/S, 1, 0
  3. Result: 55 will be in the X register.
Example 3: Factorial (n!)

This program calculates the factorial of a number N. It uses a loop and a temporary memory register.

Program (LBL 12 - Main):

  1. Enter Program Mode: P/R, 1, 2
  2. Record: 1, SWAP, GSB, 1, 3

Program (LBL 13 - Loop):

  1. Enter Program Mode: P/R, 1, 3
  2. Record: STO 00, *, RCL 00, 1, -, x>0?, GTO, 1, 3, DROP, RTN

To Run:

  1. Enter N: 5, ENTER
  2. Run: R/S, 1, 2
  3. Result: 120 will be in the X register.
Example 4: Quadratic Formula

This program solves for the roots of ax² + bx + c = 0. It calculates both roots and leaves them in the X and Y registers. It correctly handles both real and complex roots automatically.

Setup: First, store your coefficients in memory registers.

  • Enter a, then STO, 0, 0
  • Enter b, then STO, 0, 1
  • Enter c, then STO, 0, 2

Program (LBL 14):

  1. Enter Program Mode: P/R, 1, 4
  2. Record:
    • RCL 01, (b²)
    • 4, RCL 00, * (4a)
    • RCL 02, * (4ac)
    • - (d = b² - 4ac)
    • STO 03 (store d)
    • SQRT (sqrt(d))
    • RCL 01, CHS (-b)
    • + (-b + sqrt(d))
    • 2, RCL 00, * (2a)
    • / (root 1)
    • RCL 01, CHS (-b)
    • RCL 03, SQRT (sqrt(d))
    • - (-b - sqrt(d))
    • 2, RCL 00, * (2a)
    • / (root 2)
    • SWAP (root 1 in X, root 2 in Y)
  3. Exit: P/R

To Run (for x² + 2x + 5 = 0, which has complex roots):

  1. Store coefficients: 1 STO 00, 2 STO 01, 5 STO 02
  2. Run: R/S, 1, 4
  3. Result: The program will end. X will contain -1+2i and Y will contain -1-2i.
2 Likes

we fr gonna make muos handhelds an everyday item :sob:
i like the idea of a calculator, but whos exactly gonna use a calculator on muos

you can use it as a excuse to bring it in class

1 Like