FormulaCalc  A Formula Calculator for the Palm OS
Version 1.1^{*}
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 really
should read this entire document to fully understand 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:
 frmclc11.prc
 The executable file
 MathLib.prc
 The required mathematics library  V1.1
 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 frmclc11.prc. If you are upgrading FormulaCalc Version 1.0
(frmclc10.prc) you must first delete FormulaCalc V1.0 or risk requiring a Palm OS reset.
FormulaCalc requires MathLib.prc^{*}. If you have MathLib.prc already installed (because
some other application uses it) just install frmclc11.prc. Otherwise install both frmclc11.prc and
MathLib.prc.
The included MathLib.prc is the latest version (V1.1 dated 4/14/1999). You may update with this one
if you desire.
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 input area is also called the pen store.
 The four 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
nonprinting formula comment.
 Reg  pops up another window showing the values of the 26 registers A  Z.
The values are changed by hightlighting a value and modifying it.
 Pen  toggles the active input between the input area (i.e. pen
store) formulas and the routine selected from the Memo Pad memo entitled: Formula
Calculator (i.e. memo store). Pressing this button at first will do nothing
since you do not have a memo entitled Formula Calculator in your memo pad. After you
establish a memo the button name will switch between Pen and Memo to indicate which
formulas are active.
If you want to use FormulaCalc as a simple calculator:
 Tap the left side of the input area,
 Tap the 123 in the lower right of the graffiti area,
 Enter your formula,
 Tap Done,
 Tap Compute.
Your First Routine
This is an interactive trial so 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 immediate goal of clearing the input area. Now with the pen and enter:
3*47/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^2 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*47/3
 a=2; sr(a); a^2
 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.
You are now an expert!
To prove that see if you understand the example on the right.
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:

string:  " " [ ]

String function:
st(string,string,exp)
st(string,exp,exp)
st(exp,string,exp)
when a st(,,control) control evaluates 0 the result is stored but not printed. This holds all strings
from being printed until a st(,,control) control evaluates to non0 is excuted. Thus st("","",0) is a 'stop
string display command'.
Strings cannot be assigned to a letter.
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 FormulaCalc
Menu Actions
Commands
The first three commands refer to routines stored in a Memo Pad entry. Your
routines are stored in the Memo Pad under the name "Formula Calculator".
( 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.
 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.
 Prefs...  pops up the Preferences window discussed next.
This menu selects:
 the number of decimal digits displayed for number,
 control over number notation  fixed or scientific,
 whether trigonometric function use degrees or radians,
 whether or not values assigned to registers are displayed.
There are two sections to this menu: 1) settings take place now, or 2) 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.
The 'Show Exponent' value determines when the notation is switched between fixed to scientific
notation. The Trim check box determines if trailing 0's in scientific notation are displayed.
For the preferences shown the above screen, the notation will switch from fixed notation to
scientific notation when the number would be displayed with an e5.
For example:
 12345.6789 will display as 12345.68, but 123456.789 will display as 1.23e5
 10000.001 will display as 10000.00, but 100000.001 will display as 1e5
 Unchecking the Trim check box: 100000.001 will display as 1.00e5
Edit
The actions of the Edit Menu work only with the Pen Store.
 Copy  The highlighted pen store characters are copied to the clipboard. In the
special case that nothing is highlighted, the value of the result register (R) is copied.
 Cut  Same as Copy except the highlighted characters are deleted from the pen store.
 Paste  The characters in the clipboard are pasted into the pen store at the cursor
location.
 Undo  This undoes the last Paste or Cut action.
 Clear Regs  This clears all registers to 0.0.
Info
 Help  This displays a short summary about how to write well formed FormulaCalc
formulas.
 About  This displays the version and build numbers of FormulaCalc. To be sure that
your version is uptodate check the Bld: number of FormulaCalc at:
http://davidbray.org/palm/
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:
Formula Calculator (the first line and column 1 of the entry  be sure there are no leading
spaces). 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:
Formula Calculator
#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: Formula Calculator (actually only "Formula" is needed).
The name of the routine is Compound Interest.
Next is a 2 line nonprinting 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 Annunity.
As many routines as desired may be in the memo. Each must start with a #.
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
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]
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]
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 (015)  e.g. dd:4 [ ]
 se:
 set exponent to display scientific notation (015)  e.g. se:4 [ ]
 sr:
 set show register assignments (y or n)  e.g. sr:y [ ]
comment:
 " "
 printing comment  e.g. "answer is:" [answer is:]
 [ ]
 nonprinting comment  e.g. [debug line] [ ]
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 three 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 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 restored in u, and the current
value of v is multiplied by 2 and restored 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 2:
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; se:10
i=int(z/100); i=2i+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 3:
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 Program Comments
dd:6; se:10; sr:n 2 decimal digits, no scientific notation, no register values
i=int((z+11867216.25)/36524.25); number of centuries
i=z+1+iint(i/4);i=i+1524; leap days
j=int((i122.1)/365.25) a year value
m=int(365.25*j); k=int((im)/30.6001)
i=imint(30.60001*k) day of the month
m=if(k<13.5,k1,k13); month number
if(m>2.5,j4716,j4715)+(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 j4716 otherwise it is j4715. 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.101500. That is, noon on October 15, 1999.
FormulaCalc was created by
David W. Bray, Potsdam, NY;
Copyright © 19992004 David W. Bray, All Rights Reserved.
The Bray Palm OS Page can be found at:
http://davidbray.org/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.
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 program is provided without warranty and the user accepts full responsibility for
any damages, consequential or otherwise, resulting from its use.
Foot Notes
^{*}Program Changes in Version 1.1
FormulaCalc Version 1.1 differs from Version 1.0 in:
 Display of numbers can be up to 15 digits instead of 9. (V1.1 Bld:335)
 Display of numbers can be in either fixed or scientific notation. (V1.1 Bld:335)
 Added control function SE: to select the exponent at use scientific notation. (V1.1 Bld:335)
 Added DD: SR: SE: save/restore action so that their values are restored after computing a
routine. (V1.1 Bld:335)
 Added "Clear Regs" menu command. (V1.1 Bld:340)
^{*}MathLib
Many thanks to Rick Huebner, the author of MathLib, for his excellent routines and making
them freely available.