Craig A. Finseth, fin@finseth.com.
This documentation covers the Loki in RealBasic calculator. Loki is an RPN calculator that handles units and fractions. Other versions of this and similar calculators can be found at the Loki site. Enjoy.
Loki is provided as free software under the GNU Public License. Both the binary RealBasic project file and an XML dump (which includes full source) are provided as part of the distribution. RealBasic can be obtained from the RealBasic site.
Installation: just copy the
file somewhere convenient and run it. Also copy the loki.dat file to the same direcdory as the application. No other files are required. On Macintosh systems, be sure to use the Finder (or equvalent tool) for the copying.
The file RPN.html provides a quick introduction to RPN.
Copyright 2002,3 by Craig A. Finseth.
Almost all commands can be given from the keyboard. The available keys are as listed.
key | operation |
space, CR, LF, Enter | Enter |
BS, DEL | erase last character |
0-9, ., ,, e, - | enter number |
! | factorial |
# | clear X |
: | start group name |
; | start unit name |
% | percentage |
* | multiplication |
+ | addition |
- | subtraction |
/ | division |
\ | compute reciprocal (with respect to the base unit) |
@ | clear all |
D | compute delta percent |
F | enter fraction separator |
H | compute hypotenuse, given sides in X and Y |
I | compute side, given hypotenuse in Y and side in X |
L | recall last X |
N | enter current time |
P | enter PI |
R | roll down |
S | swap X and Y |
T | enter current date |
U | enter unit separator |
[ | square root |
] | square |
{ | cube root |
} | cube |
~ | negation; change sign (shows as +/-) |
For ease of typing, you can manually enter group and unit names. To enter a group name, start with a ":" character and type enough of the group name to be unique, then finish with a Space, CR, or LF. The same works for units (names within the current group) but you start with a ";" character.
Loki operates as a standard RPN calculator. However, it's extended capabilities take a little explaining. These capabilities fall into the areas of input, operators, and display.
If the Units box is not checked, the calculator works like a normal one. If the box is checked, the calcualator tracks units in the calculations. Checkboxes control the display of an input unit selector window and the output unit display window.
Loki's unit operations are designed to make life easy in situations which you come across in the real world. For example, you can square a distance unit to get an area. However, if you enter nonsense, you'll get nonsense back: adding a mass to an angle gives a result, but probably not a useful one.
It should be re-emphasized that Loki's calculations are correct, but possibly unexpected. If results are not what you expect, look more closely at what you are asking it to do. For example, if you have 4 cups and do an inverse (1/x), you'll get 4466359.8878154401 cup.
What?? you ask. Well, consider first that it is not useful to take the inverse of a volume in the real world. Thus, the "correct" answer is not obvious. What Loki does is to compute the mathematical inverse of the value. As volumes are expressed in cubic meters internally, Loki represents 4 cups as 0.00094635 m^3. Taking the inverse of this value gives 1056.68820943 m^3, which is the above value.
One other thing to keep in mind is that the default unit entry is whatever is set in the Unit Selection window. The default is not the unit of the value in the X register.
Essentially, you enter numbers as you would expect to. For example, if the input units were deg:min:sec, you could enter the value 45 degress 30 minutes 14 seconds a value as:
4 5 u 3 0 u 1 4
Note that the u key represents any units separator. If a value has only one separator (e.g., feet and inches), you use u once. If a value has two separators (e.g., h:m:s), you use u twice. If the unit has no separators (e.g., inches), you don't use the u key. Most units don't have separators.
Each of the numbers (45, 30, and 14) is itself entered as an arbitrary fraction. The three values are scaled internally before being converted to standard form. In this example, the program does:
45 + 30/60 + 14/3600
...and the whole value converted to radians (the standard angle form).
Any value can be entered as a fraction. Fractional values are entered as:
integer ab/c numerator ab/c denominator
Again, each of the integer, numerator, and denominator values can be an arbitrary number. The program performs the obvious calculation (integer + numerator/denominator) to determine the value.
If any of the components are missing, the program supplies defaults according to the following table.
ab/c ab/c | zero |
ab/c ab/c D | zero (0 + 0 / D) |
ab/c N ab/c | N / default denominator |
ab/c N ab/c D | N / D |
I ab/c ab/c | I |
I ab/c ab/c D | I / D |
I ab/c N ab/c | I + N / default denominator |
I ab/c N ab/c D | I + N / D |
Numbers are what you would expect:
These combinations permit some weird results: you can have up to three of each form of fraction mark in a number, and up to 9 radix and/or EEX marks!
All of the operators work in the obvious manner: + performs addition, * performs multiplication, etc. However, some have special properties when used with certain unit groups. These special combinations are listed in the following table.
square root | area | Results in a distance. |
square | distance | Results in an area. |
cube root | volume | Results in a distance. |
cube | distance | Results in a volume. |
addition | date, any | Computes the new date from the base date plus (or minus) the specified number of days, using the actual calendar. The result is a date. |
temperature, any | Adds any as a delta temperature to the first value. Thus, 5oC plus 9oF gives 10oC, not around 280oC. | |
subtraction | date, date | Computes the number of days between the dates, using the actual calendar. The result has no unit. |
date, any but date | Computes the new date from the base date minus (or plus) the specified number of days, using the actual calendar. The result is a date. | |
temperature, any | Subtracts any as a delta temperature from the first value. | |
multiplication | distance, distance | Results in an area. |
distance, area or area, distance |
Results in a volume. | |
speed, time or time, speed |
Results in a distance. | |
data rate, time or time, data rate |
Results in a data amount. | |
division | volume, distance | Results in an area. |
volume, area | Results in a distance. | |
area, distance | Results in a distance. | |
distance, time | Results in a speed. | |
data amount, time | Results in a data rate. | |
percent, delta percent, diagonal, and inverse | any | ignore units |
Values are stored internally in a standard form along with their type group information. For example, all distance values are stored in meters and all mass values are stored in kg. (Well, except for temperatures, which are special-cased: see the preceeding section.)
When a value is displayed, the program iterates over all units in that group. It converts to and displays each unit. Careful observation will show that the display unit(s) are completely separate from the input unit.
When a value is displayed, it can be displayed in one of four ways. For these examples, a value of 1.76 and a denominator of 8 will be used.
Go to Craig Finseth's home page, http://www.finseth.com/~fin/.