RPN Documentation
1.3.0.0
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.
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.
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!
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.
When you first run the program, you're presented with a simple prompt:
The number in barckets is the topmost item of the stack. To push a number to it, just type it in and press enter.
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.
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?
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, ]
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.