FormulaCalc -- A Formula Calculator for the PalmPilot
Version 1.0
Description

FormulaCalc is a calculator which accepts algebraic formulas and computes their values.
The formulas:
- Use common algebraic expressions with the normal multiply before add rules.
- Can have up to 26 inputs from stored data.
- Can store results in up to 26 storage locations.
- Can use trigonometric, logarithmic, and other algebraic and control functions.
- Input can be by pen graffiti or from a Memo Pad memo.
It can be used as a simple calculator, or one to compute complicated routines.
We hope you find FormulaCalc useful.
About This Documentation
FormulaCalc is intuitive and easy to use. That seems to be contradicted by the size of this
documentation. It's large because of the many features and functions. But once you become
familiar with FormulaCalc we think you will agree that it is easy to use.
You must
should read this entire document to fully understand and use the many features of FormulaCalc.
For a quick start read Installation and Quick Start.
Then after trying it out please return to this documentation to learn all of the features.
Documentation Sections:
Installation
This archive file includes:
- frmclc10.prc
- The executable file
- mathlib.prc
- The required mathematics library
- FormulaCalc.html
- This file
- fcDisp1.gif, fcDisp2.gif, fcExample.gif, fcMenu1.gif, fcMenu2.gif, fcPrefs.gif
- Images for FormulaCalc.html
Use your Pilot installer to install frmclc10.prc. FormulaCalc requires
mathlib.prc*. If you have mathlib.prc already installed (because some
other application uses it) just install frmclc10.prc. Otherwise install both frmclc10.prc
and mathlib.prc.
Quick Start
When you first use FormulaCalc you will be greeted with a display as shown on the right.
The display consists of 3 areas:
- The output area -- the clear upper box
- The input area -- the three lines below the box with scrolling and cutting buttons, welcoming you
to FormulaCalc
- The 4 buttons:
- Clear -- clears the output area.
- Compute -- computes the value of the active formulas and displays it in the output
area. If you press Compute at first nothing will happen because the greeting is a
non-printing formula comment.
- Reg -- pops up another window showing the values of the 26 registers A - Z.
- Pen -- toggles the active input between the input area (i.e. pen
store) formulas and the routine selected from the Memo Pad memo entitled: FormulaCalc
(i.e. memo store). Pressing this button at first will do nothing
since you do not have a memo entitled FormulaCalc in your memo pad. After you
establish a FormulaCalc memo the button name will switch between Pen and Memo.
If you want to use FormulaCalc as a simple calculator simply tape the "123" in the lower right of the
graffiti area, enter your formula, tap Done, then tap Compute.
Your First Routine
This is an interactive trial. Install FormulaCalc now and launch it.
In the text which follows, characters which you enter are blue, output values
are green, and register names are red.
For this first trial tap the diamond to the right side of the input area. This icon action
is "highlight all text in the input store". Tap it again. That cut it to the clipboard, and
accomplished our goal of clearing the input area.
Now with the pen and enter: 3*4-7/3 then press Compute.
The value 9.67 will appear in the output box. An "ordinary" calculator would
have displayed 1.666... because it would use a left to right calculation rather than computing 3*4 then
7/3 and then subtracting as we understand algebraic formulas.
Now on the second input line enter: a=2; sr(a); a*a then press Compute. The
output box now displays 4 lines: 9.67 2.00 1.41 4.00
Press the Compute and Clear buttons several times to see what happens.
Next press the Reg button. You will see that the A register
now has 2.00 and R has 4.00. That is because you stored 2 in A,
and R is the result register which contains the last
computed value 4.00.
Using the pen select register G, enter
20 and press Set Value. Now G contains 20.
Press Done. On the third input line enter G
to the end of your routine. Your routine should now read:
- 3*4-7/3
- a=2; sr(a); a*a
- g
Press Compute. You will see 20.00 added to your output lines, and
if you check the resisters (Reg button) R will be
20.00 since it is now the last result.
The largest number which can be computed is: 2147483646 (2^31-1).
Any result which is greater will be displayed as: "Not a Number".
You are now an expert!
Allowable Formula Objects
The allowable operators, functions and symbols are:
arithmetic: | + - * / ^   %;
|
functions: | sr() sq() ln() log() int() pi
|
trig: | sin() cos() tan() asin() acos() atan()
|
assignment: | = += -= *= /=
|
decision: | < <= = = >= >
|
grouping: | ( )
|
control: | ; if(,,) deg rad dd: sr:
|
comment: | " " [ ]
|
The definitions for these are given below, but it is now time for you to try FormulaCalc for yourself.
When you get puzzled or you want to save a routine for future use come back. It's all explained below.
This is the end of Quick Start.
Using the Application
Commands Menus
The first four commands refer to routines stored in a Memo Pad entry. Your
routines are stored in the Memo Pad under the name "FormulaCalc".
( See Storing Routines.)
- Open -- will pop up a window showing the names of your routines. Select the
desired routine and close the window. This will load the selected routine in the memo
store.
If there are more routine names than will fit in the window a scroll bar will appear
allowing you to move the names up or down.
- View -- will pop up a window showing the routine in the memo store. It too has
a scroll bar if needed.
- CopyTo.. -- will copy the routine in the memo store to the pen store. This
will allow you to edit small routines. The pen store is limited to 140 characters. Large
routines can be edited in the Memo Pad.
- Export -- appends the current pen store to the memo "FormulaCalc". The
memo routine is entitled "#UnNamed".
- Show... -- toggles the choice of whether or not values assigned to registers are
displayed. This menu item differs from the similar item in the Prefs window in that it
overrides any sr:X command in the routine (X is 'y' or 'n').
- Prefs... -- pops up the Preferences window discussed next.
This menu selects:
- the number of decimal digits displayed for number,
- whether trigonometric function use degrees or radians,
- whether or not values assigned to registers are displayed.
There are two sections to this menu:
- settings take place now, or
- settings take place next time you start FormulaCalc.
The Last buttons in the StartUp section, if selected, set the StartUp values as they were when
you last shut down FormulaCalc.
Edit Menu
The Edit Menu allow access to four editing operations.
These operations work with the pen store.
- Copy and Cut -- highlight the characters to be edited and and tap either Copy or Cut.
- Paste -- position the cursor and tap Paste to add the last Copy or Cut text.
Special Note: As discussed above, the last value computed is stored in register
R, and the value is also Copy'd to the Paste buffer. Therefore
you can Paste that value into the pen store.
- Undo -- tapping Undo will undo the last Cut ot Paste.
Storing Routines
You can store as many routines as desired in the Memo Pad. (Memo Pad has a limit of 4000
characters, but that is enough for many routines.)
Create a Memo Pad entry entitled:
FormulaCalc (the first line/column 1 of the entry). It can be in an category.
FormulaCalc will find it.
Each routine starts with a # sign in column 1 followed by the name e.g. #Compound
Interest.
A routine is of the form: formula followed by ; (and/or new line) followed by
formula .....
The routine is terminated by one or more blank lines.
All space characters within a formula are ignored.
Following is an example memo with two routines:
FormulaCalc
#Compound Interest
[Reg: I interest, P principle]
[N years, M periods per year]
dd:2
(1+i/m)^(m*n)*p
#Future Annuity
dd:2; ((1+i/m)^(m*n)-1)/(i/m)*p
This starts with the required title: FormulaCalc.
The name of the routine is Compound Interest.
Next is a 2 line non-printing comment as a reminder of the register contents.
dd:2 tells FormulaCalc to show 2 decimal digits in the output.
The formula follows.
The second routine in the memo is Future Annuity.
As many routines as desired may be in the memo. Each must start with a #.
A good way to create your first routine in the memo FormulaCalc is to create a memo
with only one line consisting of: FormulaCalc.
Then in the FormulaCalc application enter the desired routine in the pen store.
Open the Command Menu and tap 'Export'. This will copy the routine the memo. Open the memo and change
its name.
Operators and Functions
This explains each of the operators and function.
The operators:
arithmetic:
- +
- addition -- e.g. 4 + 8 result: [12]
- -
- negation -- e.g. -4 or subtraction e.g. 5 - 2.02 [2.98]
- *
- multiplication -- e.g. 12 * 6 [72], 121 * -7 [-847]
- /
- division -- e.g. 36 / 4.321 [8.3314]
- ^
- x to power y -- e.g. 2 ^ 3 [8]
- %
- remainder of x divided by y -- e.g. 30.25 % 5 [0.05],
30.25 % 1 [0.25] the fractional part
assignment:
- =
- register store -- e.g. a = 2 [2] -- a cumulative example
- +=
- add and store -- e.g. a += 13 [15]
- -=
- subtract and store -- e.g. a -= 9 [6]
- *=
- multiple and store -- e.g. a *= 3 [18]
- /=
- divide and store -- e.g. a /= 3 [6]
The functions:
arithmetic:
- sr()
- square root -- e.g. sr(2) [1.1414]
- sq()
- square -- e.g. sq(2) [4]
- ln()
- natural logarithm -- e.g. ln(3) [1.0986]
- log()
- base 10 logarithm -- e.g. sr(1000) [3]
- int()
- integer part -- e.g. int(30.25) [30]
- pi
- constant pi -- e.g. pi * 2 [6.283185307]
trigonometric:
- sin()
- sine -- e.g. sin(1) [0.8415]
- cos()
- cosine -- e.g. cos(1) [0.5403]
- tan()
- tangent -- e.g. tan(1) [1.5574]
- asin()
- arcsine -- e.g. asin(1) [1.5708]
- acos()
- arccosine -- e.g. acos(1) [0.0000]
- atan()
- arctangent -- e.g. atan(1.5574) [1.0]
decision -- used in if(,,):
- <
- less than -- e.g. a < 10
- <=
- less or equal -- e.g. a <= q
- ==
- equal -- e.g. 20 == w
- >=
- greater or equal -- e.g. t >= s
- >
- greater than -- e.g. d / 3 > 10 * 7 + a
The miscellaneous statements:
control:
- if(,,)
- select -- e.g. a=18; if (a<10, a, a/3)
[6] or a=9 [9]
- deg
- set trig functions to degrees -- e.g. deg [57.29577951]
- rad
- set trig functions to radians -- e.g. rad [0.017453292]
- dd:
- set number decimal digits to (0-9) -- e.g. dd:4 [ ]
- sr:
- set show register assignments (y or n) -- e.g. sr:y [ ]
comment:
- " "
- printing comment -- e.g. "answer is:" [answer is:]
- [ ]
- non-printing comment -- e.g. [debug line] [ ]
Operator Calculation Order
This section discusses the order in which operators are used for a calculation when not
controlled by parenthesis.
The computation is done in a left to right order for the operators and functions of a given
group as listed next listed next. This means that operators in a given group are computed
in turn left to right and then the results of each group computation combined as specified
by the order. Parenthesis modify the order forcing computation to be completed within the
'( )' before combining with other values. See the example which follow the table.
Group computation order:
First: | sr() sq() ln() log() int() pi
sin() cos() tan() asin() acos() atan() if(,,) deg rad
< <= = = >= >
|
Second: | * / ^   %;
|
Third: | + -
|
Last: | = += -= *= /=
|
Not Combined: | dd: sr: " " [ ]
|
Example:
a = 10; deg Left to right
b = 2 * 3 + 5 * sin(a + 30) ^ 2 - 9 * (5 + 7)
| | | | \ / | | \ /
| | | | 40 / | 12 Compute inside ()'s 1st
| | | \ / / | |
| | | 0.64 / | | Then things in First
\ / \ / / \ /
6 3.21 / 108 Then Second (leftmost)
\ \ / /
\ 10.33 / And Second Again
\ / /
16.33 / Then Third (leftmost)
\ /
-91.67 And Third Again
Finally the assignment
Examples
This section explains four examples in detail. The Julian Calendar is quite complicated but it is a
good example of register storage, the if(,,) statement and number encoding.
Example 1:
This example shows a simple computation which computes two values -- one for Celsius and the other for
Fahrenheit. The correct answer depends on the units of the input value.
There is no reason to have two separate functions.
#Temperature Conversion
[C to F and F to C]; t
"C:"; (t-32)/9*5
"F:"; t*9/5+32
Rather than changing register t you could change the pen store to:
t = 68
Then you could just change the input value in the pen store.
Example 2:
This example shows the use of arithmetic assignments to registers, and iteration.
#Powers of 2
sr:y
u += 1; v *= 2
This routine sets the output display to show register assignments. Then 1 is added to the current value
of u and re-stored in u, and the current
value of v is multiplied by 2 and re-stored in v.
Assume the initial value of the register u is 0, and v is 1.
Pressing Compute produces output of: 1 2 because 1 was added to
u and v was multiplied by 2.
Pressing Compute again produces: 2 4 and again 3
8 etc.
Powers of 2 -- 1 raised to 2 is 2, 2 raised to 2 is 4, 3 raised to 2 is 8, etc.
Example 3:
This example shows the use of the int() function (i.e. whole number extraction).
Julian Date was defined by astronomers to have a uniform date code independent of the calendar. It makes
taking the difference between 2 dates easy. (See note below.)
#Julian Date
sr:n; dd:2;
i=int(z/100); i=2-i+int(i/4)
int(365.25*z)+int(30.6001*(x+1))+y+1720994.5+i
Assume that register x (month) is 10, y (day) is 15, z (year)
is 1999 (October 15, 1999).
This routine sets the output display to not show register assignments, and to display 2 decimal digits.
It then divides the year by 100, and fills the whole number part into register i. i is then further manipulated for leap years. The result
is the integer part of a year and a month calculation, all added to the day, a constant and i.
The result displayed is: 2451466.50
It would be a good exercise to see the results of all computations by turning on the display of
registers. You do this by accessing menu/show....
The output is then: 19 -17 2451466.50
Note: A Julian Date is defined to start at noon and show the fraction of a day. So to be accurate
the day in y should be a day and a fraction. If y was 15.5 then noon on October 15, 1999 is the start of Julian Day 2451467.00
This routine is only accurate for the Gregorian calendar. A modification of this routine must be made
for dates before October 15, 1582.
Example 4: (advanced user)
This example is really too complicated but it shows the use of the if(,,) function, and it
shows how to encode 3 numbers into 1. It produces the calendar date for an Julian
date, and show the fraction of a day to two decimal places.
#Julian Calendar Application Comments
dd:6
i=int((z+1-1867216.25)/36524.25); number of centuries
i=z+1+i-int(i/4);i=i+1524; leap days
j=int((i-122.1)/365.25) a year value
m=int(365.25*j); k=int((i-m)/30.6001)
i=i-m-int(30.60001*k) day of the month
m=if(k<13.5,k-1,k-13); month number
if(m>2.5,j-4716,j-4715)+(m+i/100)/100 answer dependent on month value
The last line computes the year depending on the month. If the month is greater than
February then the year is j-4716 otherwise it is j-4715. Add to the year a fraction of the
combined month, day and fraction of a day. The form mmdddd. So the answer is yyyy.mmdddd
(where dddd means: day dd -- implied decimal point -- decimal part of the day dd). In
general, this scheme is a good way to display 3 different numbers as one number.
To see the result put 2451467.00 in register z.
Pressing Compute produces: 1999.101550. That is, noon on October 15, 1999.
Contact Info
FormulaCalc was created by David W. Bray, Potsdam, NY;
Copyright © David W. Bray 1999, All Rights Reserved.
The author may be contacted at: dbray@twcny.rr.com
Please be aware that I will not be able to help you with programming questions, but do contact
me about potential bugs.
The Bray PalmPilot Page can be found at:
http://www.40-below.com/palm/
Registering
FormulaCalc is freeware no registration is required. We hope you enjoy using it.
This archive may be freely redistributed, provided it is made available
only in its complete, unmodified form with no additional files and for
noncommercial purposes only. Any other use must have prior written
authorization from David W. Bray at dbray@twcny.rr.com.
Unauthorized commercial use includes, but is not limited to:
- FormulaCalc itself as a product for sale.
- Accompanying a product for sale.
- Accompanying a magazine, book or other publication for sale.
- Distribution with 'Media', 'Copying' or other incidental costs.
- Available for download with access or download fees.
Disclaimer
This application is provided without warranty and the user accepts full responsibility for
any damages, consequential or otherwise, resulting from its use.
Program Changes in Version 1.0
None. This is the first release.
Foot Notes
* - Many thanks to Rick Huebner, the author of MathLib, for his excellent routines and making
them freely available.