rpcalc

A reverse polish notation calculator written in Python 3.

rpcalc

A reverse polish notation calculator written in Python 3.

About

rpcalc is a stack-based reverse polish notation calculator based on the HP 11C Scientific Calculator with extended features, such as:

Contents

Installation and Execution

You will need Python 3.3 or higher to run rpcalc.

Archlinux

The latest stable version of rpcalc is available on the AUR as rpcalc-git. Install it as you would any other AUR software.

All other systems

I am working to put rpcalc on many repositories of various linux distributions. Until then, simply download the necessary files from the git repository.

Installing

Switch to the rpcalc directory, and run the following from a command shell:

python3 setup.py install

It is possible that your system calls your Python 3.3 binary something different, such as python (ArchLinux) or py33.exe (some Windows). If this is the case, replace python3 in the above example with the proper executable.

rpcalc should now be installed. Type rpcalc into a command shell to run it.

Running rpcalc for Testing

If you would prefer not to install rpcalc to your system, follow these instructions.

Switch to the rpcalc directory, and run the following from a command shell:

python3 rpcalc.py

It is possible that your system calls your Python 3.3 binary something different, such as python (ArchLinux) or py33.exe (some Windows). If this is the case, replace python3 in the above example with the proper executable.

Operation

rpcalc uses a stack for all operations. Users unfamiliar with RPN or stack-based calculation are encouraged to read Basic Example below and a general RPN tutorial (short and sweet).

Basic Example

To multiply seven by the sum of two and one million:

Your result, 7000014.0, is now the only entry in the stack. You can confirm this by pressing p or #.

Concepts

Operators

The most recent and second-most recent stack entries will be denoted x and y respectively. You can always peek inside operators.py for a more objective explanation of these functions.

Program

Stack

Arithmetic

Sequence Operators

Statistics

Constants

in rpcalc, constant operators begin with k to prevent conflicts with other operators

Logic

Trigonometry

Other

Other operations can easily be added by modifying operators.py.

Examples

Results are designated with >>>, but these are really stored in the stack and displayed only because they are the current x value.

1 Enter 2 +
>>> 3.0

2 Enter Enter Enter * *
>>> 8.0

10 ln
>>> 2.302585092994046

256 ln 2 ln /
>>> 8.0

2 Enter 256 ln w ln /
>>> 8.0

2 Enter 3 ==
>>> 0

2 Enter Enter ==
>>> 1

Command-Line Switches

FAQ

I found a bug! Let me email that to you...

Thank you, but please don't email me the bug! Make sure it's not a known issue, and write me a bug report here or if you're familiar with git: fork, fix, and file a pull request.

How do I do log base x?

A log function is not scheduled to be implemented because the functionality is already there and because there is no reason to memorize which stack item will be the base and on which item the log will operate.

You will need to use the change of base formula:

Logarithmic Change of Base Formula

256 ln 2 ln /

There's mean and med, so why are there no mode, maximum, or minimum operators?

Arithmetic mean and median return one result, which is pushed into the stack. Mode, maximum, and minimum all have the capacity to produce more than one result. There is no non-arbitrary method of deciding the order in which the multiple answers would be pushed into the stack. Answers like these would be no good if the user didn't know which answer s/he wanted or where it went in the stack. Procedurally, these functions would be easy to write, but there is no clear way to display the answer to the user.

Known Issues

Motivation

At time of writing (August 2013), no stack-based RPN existed with the features and extensibility for which the author was looking. This project is meant to be a test of git, GitHub, vim, Python 3, and Object-Oriented Programming in general.

-Quintus