descriptionA reverse Polish notation calculator for Linux and the PSP.
ownerkinghajj@gmail.com
last changeMon, 12 Jul 2010 21:43:43 +0000 (12 14:43 -0700)
content tags
add:
readme

RPN Documentation

1.3.0.0

Introduction

RPN is an easy-to-use Reverse Polish Notation calculator with a fair amount of useful features. It started out as a sort of pet project, but has become somewhat serious to me.

Even though I've never released it before, it's already up to version 1.3; at 1.0, this was a fully-function plain calculator, with not many bells and whistles. In 1.1, I added variables, and in 1.2 I ported this to the PlayStation portable. In this release, 1.3.0.0, I've ported this to the Nintendo Wii, and have fixed some potential bugs with Valgrind.

Features

Like any calculator, RPN can calculate, so it supports many operators: addition, subtraction, multiplication, division, exponentiation, bitwise operations, etc. Unlike some, however, RPN has support for commands and variables.

Commands are like operators in implementation, but are separate because they affect the calculator as a whole--it's stack, variables, etc. Operators only affect the stack. This limitation is part of the design of the program. A downside to this is that operators can only have two operands. This isn't much of a problem yet, but it may be later if one wants to add a ternary operator. For now, anything that can't be implemented as an operator should be implemented as a command.

Variables let you save the results of your expressions and keep shorthands for commonly used numbers. There are some predefined variables like PI, E, and kilobyte/kibibyte/etc. All predefined variables begin with an uppercase letter, but there are currently no limitations for a variable name except 1) it must have at least one non-numerical character, and 2) it cannot be the same as a command or operator. This gives you a lot of freedom to choose whatever name you want.

About the Program

By default, the calculator uses "long doubles" to store values. On my 64-bit Pentium D processor, this is 128 bits wide, and can hold up to about 2 ** 16383 before reaching "infinity"--a 4932 digit number. So, though this is not an arbitrary precision calculator, it should be good enough for most people. If you compile with the flag RPN_DOUBLE, however, then "doubles" will be used instead.

I'm not quite sure how portable this program is. It compiles on Ubuntu Linux, so it will likely compile on any GNU/Linux system with the right libraries. I believe that all the functions I use are POSIX, so hopefully this program can be ported easily to just about anything. The PSP port wasn't too difficult, though, and that required creating a custom input system!

Compiling

Hopefully, compiling can be as simple as "make; make install". However, you may need to make changes to the Makefile, and may need to type, for instance, "sudo make install" instead.

Compiling for the PSP should not present any difficulties if you already have a PSP SDK and toolchain installed. If not, you can find a great tutorial on the Gentoo wiki. I used it to install the toolchain and SDK on Ubuntu 7.10 without problem. See Specific Information About the PSP Port for more information about the PSP port.

Likewise, compiling for the Wii should be simple if you already have a properly setup DevkitPPC toolchain; but that's easier said than done. See Specific Information about the Wii Port for more information abouth the Wii port.

Using the Program

When you first run the program, you're presented with a simple prompt:

 [0]>

The number in barckets is the topmost item of the stack. To push a number to it, just type it in and press enter.

 [0]> PI
 [3.14159]>

Great! But this is a calculator--how do you calculate? If you don't know what Reverse Polish Notation is, look it up on Wikipedia. Done yet? Good. If you want to multiply by five, type this.

 [3.14159]> 5 *
 [15.708]>

You can even do more than one operation per line.

 [15.708]> 3 / 2 -
 [3.23599]>

But what if you want to see the whole stack?

 [3.23599] 2 1
 [1]> ps
 [ 1, 2, 3.23599, ]
 [1]>

How about removing the top item of the stack?

 [1]> pop
 [2]>

How about duplicating the top item of the stack?

 [2]> dup ps
 [2, 2, 3.23599, ]

Can you print the stack in more detail?

 [2]> psd
 [ 2.000000, 2.000000, 3.235988, ]

Thanks

Much thanks to Troy Hanson for uthash. It made the program much better, and makes implementing hash tables wonderfully simple.

The PSP port would not have been possible without the tutorials at psp-programming.com. The callback functions are almost carbon-copied form them.

The Wii port would not have been possible without the help of wiibrew.org.
shortlog
2010-07-12 Sam FredricksonCode cleanup & factoring of commands module.mastermob
2010-07-12 Sam FredricksonMinor code changes.
2010-07-12 Sam FredricksonDisplay CC when compiling modules.
2010-07-12 Sam FredricksonImproved tup build system config.
2010-07-12 Sam FredricksonCan now use the tup build system instead.
2010-07-12 Sam FredricksonRemoved unused parameter names from many functions.
2010-07-12 Sam FredricksonChanges to get RPN to compile with VS2008 again.
2009-08-24 Sam FredricksonAdded Visual Studio 9 solution.
2009-07-07 Sam FredricksonEdited Wii Makefile.
2009-05-17 Sam FredricksonChanged to version 2.0.1.0.
2009-03-31 Sam FredricksonMade Main.cpp simpler, made Commands.cpp use HasStack...
2009-03-30 Sam FredricksonRemoved unneeded #includes from various files.
2009-03-30 Sam FredricksonCorrected help information on "pv" and "pvd".
2009-03-29 Sam FredricksonChanged history.front() to CurrentStack() to make the...
2009-03-29 Sam FredricksonFixed crash in Calculator::pop() when the current stack...
2009-03-29 Sam FredricksonAdded the log operator to the help items.
...
tags
15 years ago 2.0.0.0 Official release of 2.0.0.0.
15 years ago 2.0.0.0-alpha2 Official release of 2.0.0.0-alpha2.
15 years ago last-c-version
15 years ago 1.3.1.2 Official release of 1.3.1.2.
15 years ago 1.3.1.1 Official release of 1.3.1.1.
15 years ago 1.3.1.0 Official release of 1.3.1.0. This...
15 years ago 1.3.0.2 Official 1.3.0.2 release.
15 years ago 1.3.0.1 Official 1.3.0.1 release.
15 years ago 1.3.0.0 Official 1.3.0.0 release.
16 years ago 1.2.3.5 Tagged 1.2.3.5
16 years ago 1.2.1.1 Tagged 1.2.1.1
16 years ago 1.2.2.0 Tagged 1.2.2.0
16 years ago 1.2.2.1 Tagged 1.2.2.1
16 years ago 1.2.2.2 Tagged 1.2.2.2
16 years ago 1.2.2.3 Tagged 1.2.2.3
16 years ago 1.2.3.1 Tagged 1.2.3.1
...
heads
13 years ago mob
13 years ago master