Users Guide

Introduction

WRPN is a calculator for Microsoft Windows that is modeled after the Hewlett-Packard HP-16c. This is not a Hewlett-Packard product.

Calculator face

WRPN uses Reverse Polish Notation, which uses the ENTER key instead of the "=" (equals) key.

In addition to all the functions you'd expect from an ordinary calculator, WRPN also has many features specifically designed for the computer professional:

The right-most position in the display indicates the current operating mode:

(blank) Floating Point
h Hexadecimal
o Octal
d Decimal
b Binary

WRPN Architecture

WRPN uses up to 64 bits as the internal representation for integer numbers. When dealing with floating point numbers, the numbers are stored in a typical 8 byte (64 bit) IEEE floating point format. The precision of floating point numbers is fixed, but integers can range from 1 to 64 bits in length

WRPN has 6 internal registers, 4 of which are arranged in a Last In First Out (LIFO) stack. They are:

Values pushed "off the top" of the stack (beyond stack 3) are lost. However, the value at the top of the stack is preserved when values are "popped".

The bottom of stack (the X register) is the value which is always shown in the display.

The Last X variable contains the previous value of the X register after a math operation.

There are 6 flags:

Reverse Polish Notation

Reverse Polish Notation is a mathematical notation which more closely models the way you solve algebraic equations. It uses "Enter" to separate numbers and mathematical operators appear at the end. WRPN uses a stack to store intermediate values which eliminates the need for parentheses to group intermediate calculations.

For example, to add 2 plus 3:

Tradition notation Reverse Polish Notation
2 2
+ Enter
3 3
= +

Notice that the two numbers are separated by the Enter button and that the operator (the "+" button) comes at the end.

The elegance of this notation becomes more apparent in the following example (2 + 3) x 4:

You type Shown in display X register Y register
2 2 2 0
Enter 2.0000 2 2
3 3 3 2
+ 5.0000 5 0
4 4 4 5
x 20.0000 20 0

Key Sequences

Almost every button in WRPN has three functions:

To select a "yellow" function, first use the mouse to click on the yellow f Key "f" button, then click on the desired button.

To select a "blue" function, click on the blue g Key "g" button, then click on the desired button.

The following buttons require an "argument". Which means that after you click on the button, you must also click some "digit" button (which becomes the "argument" to the function).

For example, to recall a value from register 5, you would use the following sequence:

RCL
5

The "5" never appears on the screen, because it is the argument of the RCL operator.

Certain buttons are also mapped to the keyboard; they are:

Note: Use the "*" key for ×, and "/" for ÷

The Enter button is only required to separate the numbers (and push the value onto the stack)

Operating Modes

WRPN has 5 operating modes:

Modes

Click on the HEX, DEC, OCT, or BIN buttons to enter the appropriate integer mode.

F KeyRCL key

The FLOAT function is a "yellow" function above the RCL button. FLOAT requires an argument which is the decimal precision. For example, to switch to floating point mode with 2 decimal places, enter the following sequence:

FLOAT (use f, then RCL)
2

The float mode will switch to scientific notation whenever the display would otherwise loose precision at the specified number of decimal places. To force scientific notation, enter a decimal point as the float digit. To enter a number in scientific notation use the EEX key (FKey + CHS) to enter the exponent.

Optionally, each of the operating modes can be selected from the window's Menu.

The internal representation of the numbers do change when switching between the floating point and any one of the integer modes. In some cases, the values may appear to be the same. However, do not rely on this behavior. For example, the fractional parts of floating point number will be truncated upon entering one of the integer modes... and will not be restored upon return to the floating point mode.

The range of valid input characters is shown below:

Hex [0-9] [a-f]
Float [0-9] (plus decimal point)
Dec [0-9]
Oct [0-7]
Bin [0-1]

Display

Display

While the yellow F key is pressed, the "f" indicator is shown in the bottom portion of the display. When the blue G key is pressed, the "g" indicator is shown.

The status of the overflow and carry bit indicator are shown as "C" and "G". The program mode is indicated by the "PRGM" indicator.

Control over displaying leading zeros is determined by flag 3.

Display with binary left

Display with binary right

The numeric display can only contain 32 bits on information while in the 64 bit binary mode. To indicate that more digits are present, the "mode indicator" changes from "b" to ".b" or "b.". The WINDOW key (f + Enter) and the Scroll keys (g + STO and g + RCL)are used to see the other 32 bits.

Basic/Input Functions

Function Key Description
ON ON Key No funtion. Use the normal File/Exit or the close button to exit WRPN.
f F Key Gain access to the "yellow" functions. The f button doesn't have a function of its own, it is used to change the function of another button (i.e.: the function written in yellow immediately above the button).
g G Key Gain access to the "blue" functions. It is used to change the function of a button to the function written in blue immediately below the button.
Enter Enter Key Used to terminate numeric input and push a value onto the stack.
BSP BSP Key Backspace. Erases one character of input. Also used to clear error messages from the screen.
clear PREFIX f KeyBSP Key Clear a pending two-part function. When functions that require multiple buttons are entered in error, they must be terminated in this way.
[0-9]   The digits [0-9] are used to input values or as arguments to other functions. Obviously, the OCT and BIN modes do not allow digits beyond 7 and 1 respectively.
decimal dp Key The decimal point button is only used in the Float mode.
[A-F]   The letters [A-F] are used as digits in the HEX mode.
EEX f KeyCHS Key Enter Exponent. This button is used for entering scientific notation (float mode only).
CHS CHS Key Change sign. Used to toggle between a negative and positive value. If pressed after EEX, it toggles the sign of the exponent.

Options

Function Key Description
HEX HEX Key Hexadecimal mode. All values are displayed as hexadecimal (base 16) numbers. The HEX mode does not support fractional values.
DEC DEC Key Decimal mode. All values are displayed as decimal (base 10) numbers. The DEC mode does not support fractional values. The method of representing negative numbers is discussed below.
OCT OCT Key Octal mode. All values are displayed as octal (base 8) numbers. The OCT mode does not support fractional values.
BIN BIN Key Binary mode. All values are displayed as binary (base 2) numbers. The BIN mode does not support fractional values.
FLOAT f KeyRCL Key Floating point mode. All values are displayed as floating point numbers at the requested number of decimal places. The is a "two part" function that requires a single digit [0-9] as an argument. The argument is the number of decimal places to be shown in the display. The display will automatically change to scientific notation if the requested decimal places would otherwise obscure the precision.
WSIZE f KeySTO Key Word size. Changes the internal word size (bits per word). WSIZE takes the value of the X register as the argument.
set 1's f Key1 Key Set 1's complement. Change the representation of negative numbers to 1's complement.
set 2's f Key2 Key Set 2's complement. Change the representation of negative numbers to 2's complement. This is the normal representation.
set UNSGN f Key3 Key Set to unsigned complement. Change the representation of "negative" numbers to unsigned.
show HEX f KeyHEX Key Show the value in the X register as a hexadecimal number, but remain in the current mode.
show DEC f KeyDEC Key Show the value in the X register as a decimal number, but remain in the current mode.
show OCT f KeyOCT Key Show the value in the X register as a octal number, but remain in the current mode.
show BIN f KeyBIN Key Show the value in the X register as a binary number, but remain in the current mode.
STATUS f Keydp Key Display the current status of the word size, complement mode, and user flags.
< g KeySTO Key Move the display "window" 1 bit to the left. In the binary mode, the presence of additional digits to the left is indicated by the ".b" mode indicator.
> g KeyRCL Key Move the display "window" 1 bit to the right. . In the binary mode, the presence of additional digits to the right is indicated by the "b." mode indicator.
SF g Key4 Key Set Flag. Set the flag specified in the X register to 1.
CF g Key5 Key Clear Flag. Set the flag specified in the X register to 0.
WINDOW f KeyEnter Key Move the display 32 bits in the binary mode. Window 0 is the right-most (normal) windows, and Window 1 is the left-most.

Math Functions

Function Key Description
+ Plus Key Addition. Add the value of the X register to the value of Y register and return the answer in the X register. Contents of the Y register are lost.
- Minus Key Subtraction. Subtract the value of the X register from the value of Y register and return the answer in the X register. Contents of the Y register are lost.
× Mult Key Multiplication. Multiply the value of the X register to the value of Y register and return the answer in the X register. Contents of the Y register are lost.
÷ Div Key Division. Divide the value of the X register into the value of Y register and return the answer in the X register. Contents of the Y register are lost.
Sqrt g KeyOCT Key Square root. Performs the square root of the value of the X register and returns the answer to the X register.
1/x g KeyBIN Key Inverse. Performs the inverse of the value of the X register and returns the answer to the X register. (Not available in the integer modes)
ABS g Key8 Key Absolute value. Performs the absolute value of the value of the X register and returns the answer to the X register.
RMD f Key9 Key Remainder (modulus). Performs a modulus on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost.
DBL× g KeyMult Key Double precision multiplication. Multiply the value of the X register to the value of the Y register and returns the answer split between the X and Y registers. The X register contains the right-most bits (as defined by word size), the Y register contains the left-most bits.
DBL÷ g KeyDiv Key Double precision division. Divide the value split between the Y and Z registers into the value of the X register and return the answer in the X register. The Y register contains the left-most bits (as defined by word size), the X register contains the right-most bits.
DBLR g Key9 Key Double precision remainder (modulus). Performs the modulus of the value split between the X and Z registers into the value of the X register and return the answer in the X register. The Y register contains the left-most bits (as defined by word size), the X register contains the right-most bits.

Stack/Register Functions

Function Key Description
Rol ROL Key Roll the stack down. The contents of the stack are rolled from top to bottom (and wrap around to the top).
Rol up g KeyROL Key Roll the stack up. The contents of the stack are rolled from bottom to top (and wrap around to the bottom).
X:Y XY Key Exchange X and Y. Exchange the values of the X and Y registers.
CLx g KeyBSP Key Clear the X register. The contents of the X register are set to zero.
LSTx g KeyEnter Key Last X. The previous contents of the X register are placed into the X register.
STO STO Key Store. Store the value of the X register into a "storage register". This is a "two part" function which requires a single digit [0-9][A-F] as an argument or a single digit and the decimal point [.0-.9][.A-.F]. The argument is the "name" of the register to receive the value.
RCL RCL Key Recall. Recall the value from a "storage register" into the X register. This is a "two-part" function which requires a single digit digit [0-9][A-F] as an argument or a single digit and the decimal point [.0-.9][.A-.F]. The argument is the "name" of the register from which to get the value.
Clear REG f KeyXY Key Clear registers. Clears all "storage registers". All registers are set to values of zero.

Logical Operators

Logical operators only function in one of the integer modes

Function Key Description
AND f KeyMult Key Performs a logical "and" on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost.
OR f KeyPlus Key Performs a logical "or" on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost.
XOR f KeyDiv Key Exclusive or. Performs a logical "exclusive or" on the contents of the X and Y registers. The answer is returned to the X register. The contents of the Y register are lost.
NOT f KeyMinus Key Not (1's complement). Performs a 1's complement on the contents of the X register. The answer is returned to the X register.

Bit-wise Operators

Bit operators only function in one of the integer modes.

Function Key Description
SL f KeyA Key Shift Left. Shift the bit pattern in the X register to the left. The left-most bit is preserved in the carry bit variable. The new right-most bit is replaced with a zero.
SR f KeyB Key Shift Right. Shift the bit pattern in the X register to the right. The right-most bit is preserved in the carry bit variable. The new left-most bit is replaced with a zero.
ASR g KeyB Key Arithmetic Shift Right. Shift the bit pattern in the X register to the right but preserve the left-most (sign) bit. The right-most bit is preserved in the carry bit variable.
RR f KeyD Key Rotate Right. Rotate the bit pattern in the X register to the right. The right-most bit is copied to the new left-most position and preserved in the carry bit variable.
RRn f KeyF Key Rotate Right "n" times. Rotate the bit pattern in the Y register to the right the number of times indicated by the value of the X register. The right-most bits are copied to new left-most positions. The carry bit contains the last right-most bit rotated.
RRC g KeyD Key Rotate Right with Carry. Rotate the bit pattern in the X register to the right and include the carry bit (between the left-most and right-most positions). The right-most position is preserved in the carry bit variable.
RRCn g KeyF Key Rotate Right with Carry "n" times. Rotate the bit pattern in the Y register to the right (including the carry bit) the number of times indicated by the value of the X register. The carry bit contains the last right-most bit rotated.
RL f KeyC Key Rotate Left. Rotate the bit pattern in the X register to the left. The left-most bit is copied to the new right-most position and preserved in the carry bit variable.
RLn f KeyE Key Rotate Left "n" times. Rotate the bit pattern in the Y register to the left the number of times indicated by the value of the X register. The left-most bits are copied to new right-most positions. The carry bit contains the last right-most bit rotated.
RLC g KeyD Key Rotate Left with Carry. Rotate the bit pattern in the X register to the left and include the carry bit (between the left-most and right-most positions). The left-most position is preserved in the carry bit variable.
RLCn g KeyE Key Rotate Left with Carry "n" times. Rotate the bit pattern in the Y register to the left (including the carry bit) the number of times indicated by the value of the X register. The carry bit contains the last left-most bit rotated.
MASKR f Key8 Key Mask Right. Create a right justified bit-wise mask. The number of bits in the mask is the value of the X register.
MASKL f Key7 Key Mask Left. Create a left justified bit-wise mask. The number of bits in the mask is the value of the X register.
LJ g KeyA Key Left Justify. Move the bit pattern to the left most position within the current word size. Afterwards, the number of positions shifted is put in the X register and the resulting shifted pattern is put in the Y register.
SB f Key4 Key Set Bit. Set a bit to 1 in the value of the Y register. The number of the bit to set is the value of the the X register. The answer is returned in the X register.
CB f Key5 Key Clear Bit. Clear a bit (set to 0) in the value of the Y register. The number of the bit to clear is the value of the X register. The answer is returned in the X register.
#B g Key7 Key Sum Bits. Perform a summation of the number of set (value of 1) bits in the value of the X register. Returns the answer in the X register.

Programming

The writing and editing of a program within the calculator is performed similar to recording a series of keystrokes. This recording process is started and stopped with the P/R key, which switches the display to show the program line number, followed by codes for the recorded keys. You can navigate through the program listing via the SST, BST, and GTO keys.

Recorded program lines are (optionally) saved upon exit or can be explicitly saved to a file. Loading a saved file will not only retrieve the program lines, it will also retrieve all other calculator settings. Programs lines can be printed via the File/Print Program menu item.

Running an program within the calculator is preformed by the GSB key followed by a label (0-9, A-F). A crude form of debugging is available via the SST key which allows for the application to be executed one line at a time. Program execution can be paused or stopped via the PSE and R/S keys.

Note: It is beyond the scope of this document to provide sufficient information on how to write a program for WRPN.

Function Key Description
GSB GSB Key Go to subroutine (followed by a label key). Used to launch a program
GTO GTO Key Go to label
R/S RS Key Run or Stop the program
SST SST Key Single step through a program
x:(i) f KeyGSB Key Exchange X with the value of the Index register
x:I f KeyGTO Key Exchange X with Index register
(i) f keyRS Key The value of the Index register
I f KeySST Key The I (index) register
B? f Key6 Key Test bit
RTN g KeyGSB Key Return from subroutine
LBL g KeyGTO Key Label (the target of a GTO or GSB)
DSZ g KeyHEX Key Decrement and skip on zero
ISZ g KeyDEC Key Increment and skip on zero
F? g Key6 Key Test flag (i.e. the carry bit)
P/R g KeyRS Key Switch between the Program or Run modes
BST g KeySST Key Back step through a program
PSE g KeyXY Key Pause execution to show a value
MEM f Key0 Key Remaining memory
x<=y g Key1 Key If (x <=y ) then...
x<0 g Key2 Key If (x < 0) then...
x>y g Key3 Key If (x > y) then...
x>0 g KeyMinus Key If (x> 0) then...
x!=y g Key0 Key If (x!= y) then...
x!=0 g Keydp Key If (x != 0) then...
x=y g KeyCHS Key If (x= y) then...
x=0 g KeyPlus Key If (x = 0) then...

Configuration Options

Users can optionally edit the XML-based "wrpn.config" file to change some of the calculator's features/properties. The location and exact name of this file is very much platform dependent. Android users have a built-in configuration menu (since it is often difficult to get to the wrpn.config file without a 3rd party app)

Note: Be careful, since there's no input validation to prevent bogus entries

Note: Changes do not go into effect until the program is restarted

State Files

Programs and calculator settings are stored in XML-based "saved state" files. The location of these files is platform dependent. The default name is CalcState.xml, but you create many state files. The calculator does not have a built-in feature for managing these files, so you must use the normal operating system tools to copy, move, delete, or rename these files.

Note: Editing of these files is allowed, but be careful... since there are very few input validation checks